;------------------------------------------------------------------------
;		Copyright 2010 Integrated Logic Systems
;                  Source Code is Copyright Stephen J. Carden
;
;
;			Please do not share this source!
;------------------------------------------------------------------------
;                            RealSiov.com
;
;	This is a program to will change at will the siov in RealDos
;
;
;
;		init	4/30/2010	sjc new design
;
;       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;------------------------------------------------------------------------
; 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   12,"filename.ext",$9b
			dc.b   12,"RealSiov.com",$9b
			.endm

;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; File revision history. Version Number in hex
;
file_ver:		equ   $11
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; the Month in dec for the first time this revision 
;was compiled
;
c_month:		equ   8
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; the day in dec for the first time this revision 
;was compiled
c_day:			equ   28
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; 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..yes
;
;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Gotta define if it can be relocated
r..crl:			equ	$7d
r..crlf:		equ	$9b
r..space:		equ	$20

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

EDITRV:		equ	$E400
casetbuf:	equ	$0400			; cassette Read Buffer
STACKP:		equ	$0318
SOUNDR:		equ	$41
CASFLG:		equ	$030F
TSTAT:		equ	$0319
CDEVIC:		equ	$023A
CCOMND:		equ	$023B
CAUX1:		equ	$023C
DRETRY:		equ	$02BD
CRETRY:		equ	$029C




			.include	equates
			.include	globals
			.include	macros

			.org  $4000

win_start:
header_info:
			.include	header			; this reads info out of the header and displays to screen
;								; based on info stored at the front of the file
start:
		jsr	printsi
		dc.b	$9b,$9b
		dc.b	"SIOV Menu Selected",$9b
		dc.b	"Which SIOV would you like ?",$9b
		dc.b	<+128>,"[S]"
		dc.b	" = US Doubler SIOV",$9b
		dc.b	<+128>,"[O]"
		dc.b	" = SIOV from OS!",$9B
		dc.b	<+128>,"[M]"
		dc.b	" = ILS's Fast Mux SIOV!",$9B
		dc.b	<+128>,"[I]"
		dc.b	" = ILS's NEw Fast SIOV!",$9B
		dc.b	<+128>,"[Q]"
		dc.b	" = DOS to pic's the SIOV",$9b
		dc.b	<+128>,"[A]"
		dc.b	" = Abort Siov selection & Exit",$9b
		dc.b	$9b
		dc.b	" You Selection? "
		dc.b	$9b,$9b
		dc.b	-1
.tkc1:
		lda	$2fc
		cmp	#$ff
		beq	.tkc1
		cmp	#$3e		;'S'	Load the SpartaDos siov
		beq	.SpartaSiov
		cmp	#$25		;'M'	Load the Mux Siov
		beq	.mux.siov
		cmp	#$08		;'O'	Load the OS siov
		beq	.os.siov
		cmp	#$2f		;'Q'	The program Sets the siov based on Hardware
		beq	.tkc
		cmp	#$3f		;'A'
		beq	.byby
		cmp	#$16		;'X'
		beq	.byby
		cmp	#$2a		;'E'
		beq	.byby
		cmp	#$1c		;'Esc'
		beq	.byby
		cmp	#$0d		;'I'
		beq	.sjc
		jmp	.tkc1
.tkc:
		lda	#$ff
		sta	$2fc
		jsr	interrogate
		lda	$d012			; pin 3 and 10 of gtia
		cmp	#$00
		beq	.SpartaSiov
		lda	USP_DATA
		cmp	#$FF
		beq	.os.siov1

.byby:
		lda	#$ff
		sta	$2fc
		jmp	Exit
.SpartaSiov:
		lda	#$ff
		sta	$2fc
		jmp	SPARTA_SIO
;

.mux.siov:
		lda	#$ff
		sta	$2fc
		jmp	mux_sio


.os.siov:
		lda	#$ff
		sta	$2fc
		jsr	interrogate
.os.siov1:	lda	os_type
		cmp	#$80
		bcs	.mux_sio
		jsr	printsi
		dc.b	" Loading Siov from OS!",$9B,-1
		jmp	USP_SIO
;
.mux_sio:
		lda	#$ff
		sta	$2fc
		jmp	mux_sio
.sjc:
		lda	#$ff
		sta	$2fc
;
		jsr	printsi
		dc.b	" Steve's New Siov Routeen LOADED!",$9B,$9B,-1
		jmp	steve

;
interrogate:
		jsr	start-3			; this will reprint our file info
		jsr	pal_ntsc		; Going to peek in and set 50/60 HZ
		jsr	TEST_SMARTOS		; looking to see if the SmartOS is present!
		jsr	kpi_test		; testing for kpi interface
 		jsr	BLACK_BOX		; testing for the Black Box
		jsr	MIO_TEST		; Testing for the MIO
		jsr	USP			; Testing for ram at $d700
		jsr	TEST_OS			; Let's See What Kind of OS We have here!
		jsr	ape_run			; lets see if the is an ape interface
		jsr	modem_run		; Let's see if we have an R: port
		jsr	printer_run		; Let's see if we have an P: port
		jsr	pc_run			; Let's see if we are running an emulator
		rts



;-----------------------------
;  This is the ILS SIov Routine
;-----------------------------

data_us:	dc.b	$4c,$bd,$07,$b5,20
MUX_SIO:
		jsr	printsi
		dc.b	" Multiplexer Siov Routeen LOADED!",$9B,$9B,-1
;
USP_SIO:
		ldy	#$00
.us:		lda	data_us,y
		sta	$798,Y
		iny
		cpy	#$05
		bne	.us

		lda	#low segtab1
		sta	zwptr
		lda	#high segtab1
		sta	zwptr+1
		jsr	set_block
		jsr	OS_QUIK_OFF
		jsr	relocate
w9a42:		jsr	L_E6E2
		rts
;
;-----------------------------------
; We must change 5 bytes at location
; $0798 "not_for_mux" to
;
; lda pdvmsk
; beq go_sio
;
; this is the dc.b equivlent of
; these two code lines
;
;
;-----------------------------------
;
DATA_MUX:	dc.b	$AD,$47,$02,$F0,$20
SPARTA_SIO:
		ldy	#$00
.CSS:		LDA	DATA_MUX,Y
		sta	$798,Y
		iny
		cpy	#$05
		bne	.CSS
;
		jsr	printsi
		dc.b	" US Doubler Siov Routeen LOADED!",$9B,$9B,-1
;
steve:		lda	#low segtab2
		sta	zwptr
		lda	#high segtab2
		sta	zwptr+1

		jsr	set_block
		jsr	OS_QUIK_OFF
		jsr	relocate
w9b32		JSR	S_LE6E2
		rts


exit:
		rts

;-----------------------------------------------------------------
;
;
;       Relocater: main entry
;       ---------------------
; in:
;       segtab  = table of segment descriptors
;               +00 = relocater table address
;               +02 = originate address of block
;               +04 = destination originate of block
;               +06 = address of block
;               +08 = number of bytes in block
;               +10 = destination address of block
;		+12 = Length of segment descriptor
;		+14 = this is the word location addjust memory
;
;
;
;
;       reltab  = relocater table
;               list of address of words to adjust      2 bytes each entry
;               list of address low bytes to adjust     2 bytes each entry
;               list of address high bytes to adjust    3 bytes each entry
;                       followed by their low bytes
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
relocate:
		lda	segtab+segaddress		; setting some stuff up for the relocator
		sta	segtab+dorgadr			; Passing Stuff to the relocator
		sta	segtab+blkdes			; Passing Stuff to the relocator
		lda	segtab+segaddress+1		; setting some stuff up for the relocator
		sta	segtab+dorgadr+1		; Passing Stuff to the relocator
		sta	segtab+blkdes+1			; Passing Stuff to the relocator

		lda	#0				; set ptr to segment 0
		sta	.segment			; Clearing our pointer so we can reuse
		sta	.zoffset			; Clearing our pointer so we can reuse
		sta	.zoffset+1			; Clearing our pointer so we can reuse

.segloop:	ldx	.segment
		lda	segtab+rettad,x			; get address of relocater table
		sta	.relget+1
		lda	segtab+rettad+1,x
		sta	.relget+2
		ora	.relget+1			; if zero, then end of segtab
		bne	.havseg
		rts

.havseg:	sec					; calculate offset to add to .segment
		lda	segtab+dorgadr,x
		sbc	segtab+orgadr,x
		sta	.zoffset
		lda	segtab+dorgadr+1,x
		sbc	segtab+orgadr+1,x
		sta	.zoffset+1

.zwordlp:	jsr	.getzwp
		beq	.zlbytlp			; if zero, go adjust low bytes

		lda	(zwptr),y			; add offset to address
		clc
		adc	.zoffset
		sta	(zwptr),y
		iny
		lda	(zwptr),y
		adc	.zoffset+1
		sta	(zwptr),y
		jmp	.zwordlp

.zlbytlp:	jsr	.getzwp				; get address
		beq	.zhbytlp			; if zero, then adjust high bytes

		lda	(zwptr),y
		clc
		adc	.zoffset
		sta	(zwptr),y
		jmp	.zlbytlp

.zhbytlp:	jsr	.getzwp				; get address
		beq	.zmovlp				; jump if end of table

		jsr	.relget				; get low byte
		clc
		adc	.zoffset
		lda	(zwptr),y
		adc	.zoffset+1
		sta	(zwptr),y
		jmp	.zhbytlp
		rts

.zmovlp:
		lda	.segment+segmove		; gonna check the memover
		cmp	#seg_off			; $ff we quit subroutein
		bne	..zmovlp			; most of been something other than ff do mem move
		rts					; ok time to exit subroutien 	

..zmovlp:	ldx	.segment			; get block start and to address
		lda	segtab+blkadr,x
		sta	.zmovfr+1
		lda	segtab+blkadr+1,x
		sta	.zmovfr+2

		lda	segtab+blkdes,x
		sta	.zmovto+1
		lda	segtab+blkdes+1,x
		sta	.zmovto+2

							; get # pages to move
		ldy	segtab+blkbyt+1,x

		ldx	#0
.zmovfr:	lda	$ffff,x
.zmovto:	sta	$ffff,x
		inx
		bne	.zmovfr
		inc	.zmovfr+2
		inc	.zmovto+2
		dey
		bpl	.zmovfr				; move even # pages, so may move up to 256;;
							;  bytes more than needed
		lda     .segment
		clc
		adc	#seglen				; go to next .segment
		sta	.segment
		jmp	.segloop


.relget:	lda	$ffff
		inc	.relget+1
		bne	.nc1
		inc	.relget+2
.nc1:		rts

.getzwp:	jsr	.relget				; top of word adjust loop
		sta	zwptr				; save address of word
		jsr	.relget
		ldy	#0
		sta	zwptr+1
		ora	zwptr				; check if at end
		rts

.segment:	dc.b	0				; current .segment
.zoffset:	dc.w	0				; offset to add to addresses
;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;End of relocation Table!!!
;master table:
;
segtab:
		dc.w	0				;rtable1	address of relocater table
		dc.w	0				;initz1		assembly start address
		dc.w	0				; relocate to address (filled in)
		dc.w	0				;initz1		absolute start address of block
		dc.w	0				; zend1-initz1	size of block
		dc.w	0				; destination of block (filled in)
		dc.w	0				; END of .segments
		dc.w	0				;$3000		segaddress memory to adgust by. Poke 
							; in memlow or the location in 
							; memory you want it
		dc.b	seg_off				; -1 means do not move memory!

;
segtab1:
		dc.w	rtable1				; address of relocater table
		dc.w	X_L4034				; assembly start address
		dc.w	0				; relocate to address (filled in)
		dc.w	X_L4034				; absolute start address of block
		dc.w	LE_RAM_END-X_L4034		; size of block
		dc.w	0				; destination of block (filled in)
		dc.w	0				; END of segments
		dc.w	$e459				; segaddress memory to adgust by. Poke 
							; in memlow or the location in 
							; memory you want it
		dc.b	seg_on				; -1 means do not mem move
;
segtab2:
		dc.w	rtable2				; address of relocater table
		dc.w	S_L4034				; assembly start address
		dc.w	0				; relocate to address (filled in)
		dc.w	S_L4034				; absolute start address of block
		dc.w	SE_RAM_END-S_L4034		; size of block
		dc.w	0				; destination of block (filled in)
		dc.w	0				; END of segments
		dc.w	$e459				; segaddress memory to adgust by. Poke 
							; in memlow or the location in 
							; memory you want it
		dc.b	seg_on				; -1 means do not mem move
;
set_block:	ldy	#$00
.a:		lda	(zwptr),y
		sta	segtab,y
		iny
		cpy	#16+1
		bne	.a
		rts
;
;
;
rtable1:
		dc.w	w9a01+1
		dc.w	w9a02+1
		dc.w	w9a03+1
		dc.w	w9a04+1
		dc.w	w9a05+1
		dc.w	w9a06+1
		dc.w	w9a07+1
		dc.w	w9a08+1
		dc.w	w9a09+1
		dc.w	w9a10+1
		dc.w	w9a11+1
		dc.w	w9a12+1	
		dc.w	w9a13+1
		dc.w	w9a14+1
		dc.w	w9a15+1
		dc.w	w9a16+1
		dc.w	w9a17+1
		dc.w	w9a18+1
		dc.w	w9a19+1	
		dc.w	w9a20+1
		dc.w	w9a21+1
		dc.w	w9a22+1
		dc.w	w9a23+1
		dc.w	w9a24+1
		dc.w	w9a25+1
		dc.w	w9a26+1
		dc.w	w9a27+1
		dc.w	w9a28+1
		dc.w	w9a29+1
		dc.w	w9a30+1	
		dc.w	w9a31+1
		dc.w	w9a32+1
		dc.w	w9a33+1
		dc.w	w9a34+1
		dc.w	w9a35+1
		dc.w	w9a36+1
		dc.w	w9a37+1
		dc.w	w9a38+1
		dc.w	w9a39+1
		dc.w	w9a40+1
		dc.w	w9a41+1
		dc.w	w9a42+1

		dc.w	0
		dc.w	0
		dc.w	0
		dc.b	0

rtable2:
		dc.w	w9b01+1
		dc.w	w9b02+1
		dc.w	w9b03+1
		dc.w	w9b04+1
		dc.w	w9b05+1	
		dc.w	w9b06+1	
		dc.w	w9b07+1
		dc.w	w9b08+1
		dc.w	w9b09+1
		dc.w	w9b10+1
		dc.w	w9b11+1	
		dc.w	w9b12+1
		dc.w	w9b13+1
		dc.w	w9b14+1	
		dc.w	w9b15+1
		dc.w	w9b16+1
		dc.w	w9b17+1
		dc.w	w9b18+1
		dc.w	w9b19+1
		dc.w	w9b20+1
		dc.w	w9b21+1
		dc.w	w9b22+1
		dc.w	w9b23+1
		dc.w	w9b24+1
		dc.w	w9b25+1
		dc.w	w9b26+1
		dc.w	w9b27+1	
		dc.w	w9b28+1
		dc.w	w9b29+1
		dc.w	w9b30+1
		dc.w	w9b31+1
		dc.w	w9b32+1

		dc.w	0
		dc.w	0
		dc.w	0
		dc.b	0


;-----------------------------------------------------------------
;
;  Checking on the black box if it is present!
;
;-----------------------------------------------------------------
BLACK_BOX:
		sei
		lda	#2
		sta	BB_Sensel
		ldy	#$10
Y7008:
		ldx	#2
		lda	pbi_rom,Y
		cmp	Y703B,X
		beq	Y7016
		iny
		bne	Y7008
		jmp	Y7033
		rts
;
Y7016:
		iny
		dex
		bmi	Y7024
		lda	pbi_rom,Y
		cmp	Y703B,X
		bne	Y7008
		beq	Y7016
Y7024:
Y7031:
		jsr	printsi
		dc.b	" Black Box IS present in system!",$9B,-1
;
Y7033:
		cld
		lda	#0
		sta	BB_Sensel
		cli
		rts
;
Y703B:		dc.b	$D0,$08,$29,$00
;
;-----------------------------------------------------------------
;routine to check for the kpi
;-----------------------------------------------------------------
;
kpi_test:
		sei
		lda	#$28
		sta	PBIBANK			;turn on ram and printer code bank
		lda	pbi_ram+1
		cmp	#'C'
		bne	no_kpi
		lda	pbi_ram+7
		cmp	#'K'          		;as in KProducts in the ram string
		bne	no_kpi       		;if it ain't there then get out
		jsr	printsi
		dc.b	" KPI interface IS present in system!",$9B,-1
		lda	#$00
		sta	$d1ff        		; added code for Ken
no_kpi:
		cli
		rts                    		;or whichever way you need to return
;
;------------------------------------------------------------------
;checking for pal/ntsc machines
;-----------------------------------------------------------------
pal_ntsc:
		lda	$d014
		ora	#$f0			; masking high order bytes
		cmp	#$ff			;
		beq	.ntsc
		bne	.pal
		rts
.ntsc:
		jsr	OS_QUIK_OFF
		lda	#60
		sta	$ff89
		jsr	OS_QUIK_ON
		jsr	printsi
		dc.b	" NTSC Detected Setting To 60hz",$9B,-1
		rts
.pal:
		jsr	OS_QUIK_OFF
		lda	#50
		sta	$ff89
		jsr	OS_QUIK_ON
		jsr	printsi
		dc.b	" PAL Detected Setting To 50hz",$9B,-1
		rts
;
;------------------------------------------------------------------
;      Check to see if we are running on an emulator
;-----------------------------------------------------------------
pc_run:
		ldy	#$00
loap_1:		lda	$031a,y
		cmp	#'H'     ; WAS THE EDITOR
		beq	get_vec
		iny
		iny
		iny
		cpy	#36
		bne	loap_1
		rts
;
get_vec:
		lda	#$ff
		sta	USP_DATA
		jsr	printsi
		dc.b	" PC Emulator Detected!",$9B,-1
		rts
;
;------------------------------------------------------------------
; Ape Test
;-----------------------------------------------------------------
ape_run:
		lda	tammys_os
		CMP	#$88
		bne	tuc
		rts
tuc:
		jsr	get_ape             		; get date/time
		bmi	ape_ero             		; error during time download!
		jsr	printsi
		dc.b	" Ape Interface Detected!",$9b,-1
		lda	#$ff
		sta	usp_data
ape_ero:	ldx	#$0b
ap_ro:		LDA	cmdtab1,x
		sta	$300,x
		dex
		bpl	ap_ro
		rts
;
; Attempt to download time from APE.
;
get_ape:
		ldx	#$0b
get_ape1:	lda	$300,x
		sta	cmdtab1,x
		dex
		bpl	get_ape1
;
		ldx	#$0B				; setup the download command
ap_set:		lda	cmdtab,x
		sta	$300,x
		dex
		bpl	ap_set
		clc
		jmp	$e459
;
tammys_os:	dc.b	0
;
cmdtab:		dc.b	$45,$01,$93,$40,$00
		dc.w	cmdtab2
		dc.w	6
		dc.b	$00,$EE,$A0
cmdtab1:	dc.b	0,0,0,0,0,0,0,0,0,0,0,0,0
cmdtab2:	dc.b	0,0,0,0,0,0
;------------------------------------------------------------------
;      Check to see if we have a modem
;-----------------------------------------------------------------
modem_run:
		ldy	#$00
laap_1:		lda	$031a,y
		cmp	#'R'				; Checking for R: device
		beq	get1_vec
		iny
		iny
		iny
		cpy	#36
		bne	laap_1
		rts
;
get1_vec:
		jsr	printsi
		dc.b	" R: Handler Detected",$9B,-1
		rts
;
;------------------------------------------------------------------
;      Check to see if we have a Printer
;-----------------------------------------------------------------
printer_run:
		ldy	#$00
paap_1:		lda	$031a,y
		cmp	#'P'				; Checking for P: Device
		beq	pet1_vec
		iny
		iny
		iny
		cpy	#36
		bne	paap_1
		rts
;
pet1_vec:
		jsr	printsi
		dc.b	" P: Handler Detected",$9B,-1
		rts
;
;------------------------------------------------------------------
;  This Routeen Tests for a MIO in system
;-----------------------------------------------------------------
MIO_TEST:

		sta	mio_acc
		sty	mio_y
		stx	mio_x
		tsx
		stx	mio_stack
		sei

		lda	$14
tammy:		cmp	$14
		beq	tammy
		SEC					; DISSABLE ALL INTRUPES
		lda	Ld1e0
		sta	M_HOLD
		lda	Ld1e2
		sta	M_HOLD+1
		lda	#$00
		sta	Ld1e0
		lda	#$20
		sta	Ld1e2
		lda	#'C'
		cmp	pbi_ram+1
		bne	NO_MIO
		cmp	pbi_ram+10
		bne	NO_MIO
		lda	#$01
		sta	mio_there

NO_MIO:
		lda	#$00          			; this reselects the mio to be enabled
		sta	$d1e0
		sta	$d1e2
		CLI

		ldx	mio_stack
		txs
		lda	mio_acc
		ldy	mio_y
		ldx      mio_x
		lda	mio_there
		cmp	#$00
		beq	_exit


		jsr	printsi
		dc.b	" ICD MIO Present in System!",$9B,-1

_exit:

		rts


M_HOLD:		dc.b	0,0

mio_acc:	dc.b	0		; accumlator
mio_y:		dc.b	0		; Y register
mio_x:		dc.b	0		; x register
mio_stack:	dc.b	0		; hold the stack
mio_there:	dc.b	0		; holding reg for mio test
;

;-----------------------------------------------------------------
; Need to test for ram at D7xx
;-----------------------------------------------------------------
;
USP_DATA:	dc.b	0,0
os_type:	dc.b	0
USP:
		lda	$D79D
		sta	USP_DATA+1
		lda	#$04
		sta	$D79D
		cmp	$D79D
		bne	NO_USP
		lda	USP_DATA+1
		sta	$D79D
		lda	#$FF
		sta	USP_DATA
		jsr	printsi
		dc.b	" Ram Detected at $D7xx ",$9B,-1
;
NO_USP:		RTS
;
;-----------------------------------------------------------------
;off = 1   on = 0
;-----------------------------------------------------------------
gtia_mux:
		lda	$d012
		cmp	#$01
		beq	.a
		jsr	printsi
		dc.b	" Mux Disable switch "
		dc.b	<+128>,"ON"
		dc.b	$9b,-1
.a:
		rts
;
gtia_usp:
		lda	$d012
		cmp	#$01
		beq	.a
		jsr	printsi
		dc.b	" USP booting from ramdisk "
		dc.b	$9b,-1
.a:
		rts
;
;-----------------------------------------------------------------
;Let look through all the OS to configure the Siov that is best
;-----------------------------------------------------------------
;
TEST_OS:
		lda	$CFFE
		sta	tammys_os
		cmp	#$10			; xl os detected
		bne	.USP1
		lda	$E459+1
		cmp	#$33
		beq	.USPA
		cmp	#$70			; gotta look for My IDE interface
		beq	.USPa			; use to be bne.
		lda	#$00			; 00 for high speed siov $ff for slow
		sta	USP_DATA
		lda	#$01
		sta	os_type
		jsr	printsi
		dc.b	" Standard OS Detected",$9B,-1
		rts
;
.USPA:		jmp	.USP6
;
.USP1:
		cmp	#$FE			; turboss detected
		bne	.USP2
		lda	#$00			; 00 for high speed siov $ff for slow
		sta	USP_DATA
		lda	#$02
		sta	os_type
		jsr	printsi
		dc.b	" Turboss OS Detected!",$9B,-1
		rts
;
.USP2:
		cmp	#$90			; Mux
		bne	.USP3
		lda	#$FF			; 00 for high speed siov $ff for slow
		sta	USP_DATA
		lda	#$80
		sta	os_type
		jsr	gtia_mux
		jsr	printsi
		dc.b	" Mux OS Detected!",$9B,-1
		rts
;
.USP3:
		cmp	#$88			; usp
		bne	.USP4
		lda	#$00			; 00 for high speed siov $ff for slow
		sta	USP_DATA
		lda	#$07
		sta	os_type
		jsr	my_wait
		jsr	gtia_usp
		jsr	printsi
		dc.b	" Ultra Speed Plus OS Detected!",$9B,-1
		lda	$D79D
		cmp	#$80			; USP Ramdisk Flag
		bne	.NNR4
		lda	#$04			; Normal Drive 4
		sta	$D79D
		jsr	my_wait
		jsr	printsi
		dc.b	" D4: Ramdisk Removed, D4: Installed!",$9B,-1
.NNR4:		RTS
;
.USP4:
;
		cmp	#$00			; omnimon
		bne	.USP5
		ldy	$CDA5
		cpy	#$60
		beq	.TBPLUS
;
		lda	#$00			; 00 for high speed siov $ff for slow
		sta	USP_DATA
		lda	#$04
		sta	os_type
		jsr	printsi
		dc.b	" Omnimon OS Detected!",$9B,-1
		rts
;
.TBPLUS:
		lda	#$00			; 00 for high speed siov $ff for slow
		sta	USP_DATA
		lda	#$03
		sta	os_type
		jsr	printsi
		dc.b	" Turboss + OS Detected!",$9B,-1
		rts
;
.USP5:
;
		cmp	#$F3			; omniview
		bne	.USPAA
		lda	#$00			; 00 for high speed siov $ff for slow
		sta	USP_DATA
		lda	#$05
		sta	os_type
		jsr	printsi
		dc.b	" OmniView OS Detected!",$9B,-1
		rts
;
.USPAA:		jmp	.OSDT
;
.USP6:
		lda	$e459+1
		cmp	#$70			; gotta look for My IDE interface
		bne	.USP7
		lda	#$FF			; 00 for high speed siov $ff for slow
		sta	USP_DATA
		lda	#$82
		sta	os_type
		jsr	printsi
		dc.b	" My IDE 3.1 OS Detected!",$9B,-1
		rts
.usp7:

		lda	$e459+1
		cmp	#$8f			; gotta look for My IDE interface
		bne	.USP8
		lda	#$FF			; 00 for high speed siov $ff for slow
		sta	USP_DATA
		lda	#$81
		sta	os_type
		jsr	printsi
		dc.b	" My IDE 4.2 OS Detected!",$9B,-1
		rts




.USP8:
		cmp	#$08			; Looking for Ape Warp OS
		bne	.OSDT
		lda	#$00			; 00 for high speed siov $ff for slow
		sta	USP_DATA
		lda	#$06
		sta	os_type
		jsr	printsi
		dc.b	" Ape Warp + OS Detected!",$9B,-1
		rts
.OSDT:
		lda	#$00
		sta	USP_DATA
		jsr	printsi
		dc.b	" Unknown OS Detected",$9B,-1
		rts
;
;
;
MY_WAIT:
		lda	RTCLOK+2
.A:		CMP	RTCLOK+2
		bne	.A
		RTS
;
;------------------------------------------------
; TEst of the SmartOS board
;-----------------------------------------------------------------
TEST_SMARTOS:
		lda	$D011
		sta	SMOS_DATA+2
;
		jsr	MY_WAIT
		lda	PORTB
		sta	SMOS_DATA+1
;
		php
		sei
		lda	NMIEN
		pha
		lda	#$00
		sta	NMIEN
;
		lda	SMOS_DATA+2
		cmp	#$01
		beq	NOT_IN_ROM
		lda	#$40
		sta	SMOS_DATA
;
NOT_IN_ROM:
		lda	#$A0
		sta	SMARTOS
		lda	#$FF
		sta	Char_Set
		lda	Char_Set
		cmp	#$FF
		beq	SMOS_HERE
;
		pla
		sta	NMIEN
		plp
		lda	SMOS_DATA+1
		sta	PORTB
		cli
		rts
;
SMOS_HERE:
		lda	#$00
		sta	char_Set
		lda	SMOS_DATA
		sta	SMARTOS
;
		pla
		sta	NMIEN
		plp
		lda	SMOS_DATA+1
		sta	PORTB
		cli
;
		jsr	MY_WAIT
		jsr	MY_WAIT
		jsr	MY_WAIT
;
		jsr	printsi
		dc.b	" Smart OS Detected in ",-1
		lda	SMOS_DATA
		cmp	#$40
		bne	.NOT_IN_ROM
		jsr	printsi
		dc.b	"Rom Mode!",$9b,-1
		rts
;
.NOT_IN_ROM:
		lda	SMOS_DATA
		cmp	#$80
		bne	.NOT_IN_RAM
		jsr	printsi
		dc.b	<+128>,"Ram"
		dc.b	" Mode!",$9b,-1
.NOT_IN_RAM:
		rts
;
SMOS_DATA:	dc.b	$80,0,0
;
;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;   OS on and off ROUTEEN	      
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;

os_off:
		SEI	
		lDA	PORTB
		AND	#$FE
		STA	PORTB
		CLI	
		RTS	
;
os_on:
		SEI	
		lDA	PORTB
		ORA	#1
		STA	PORTB
		CLI	
		RTS	

;
OS_QUIK_ON:	lda	PORTB
		ora	#1
		sta	PORTB
		rts
;
OS_QUIK_OFF:	lda	PORTB
		and	#$FE
		sta	PORTB
		rts


;
upcase:		cmp	#'a'
		bcc	.xupcase
		cmp	#'z'+1
		beq	.xupcase
		bcs	.xupcase
		sec
		sbc	#32
.xupcase:	rts

;       Get character 
;       ------------- 
; out: 
;       A       = character (all others preserved) 
; 
GET_KEY:  JSR ZGETCH
ZCH:      LDA #0
         RTS 
; 
ZGETCH:   JSR SAVER
         JSR ZPHG
         STA ZCH+1
         JMP RESALL
; 
ZPHG:     LDA $E425
         PHA 
         LDA $E424
         PHA 
         RTS 
; 
;

; 
; 
;================================= 
;       print/input routines 
;================================= 
; 
;       Print character 
;       --------------- 
; in: 
;       A       = character to print 
; out: 
;       all registers preserved 
; 
ECHO:     JSR SAVER
         JSR ZOUT
         JMP RESALL
; 
ZOUT:     STA ZTEMP+1
         LDA $0347
         PHA 
         LDA $0346
         PHA 
ZTEMP:    LDA #0
         LDX #0			;1      ; force NO output to PRINT Dn: 
         RTS 
; 

; 
; 
;       Print text 
;       ---------- 
; out: 
;       all registers preserved 
; notes: 
;       This print routine will print all characters 
;       following the JSR PRINT until a delimiter of 
;       -1 ($FF) is reached. PRINT will return to the 
;       point one byte beyond the delimiter. 
; 
printsi:
         JSR SAVER
         TSX 
         LDA $0105,X
         STA ZOCH+1
         LDA $0106,X
         STA ZOCH+2
; 
         LDY #1
ZOCH:     LDA $FFFF,Y
         CMP #$FF
         BEQ ZECHO
         JSR ECHO
         INY 
         BNE ZOCH
ZECHO:    TYA 
         CLC 
         ADC $0105,X
         STA $0105,X
         LDA $0106,X
         ADC #0
         STA $0106,X
         JMP RESALL
; 
; 
; 

; 
; 
;       SAVE & RESTORE registers 
;       ------------------------ 
; 
SAVER:    PHP 
         PHA 
         PHA 
         PHA 
         PHP 
         PHA 
         TXA 
         PHA 
         TSX 
         LDA $0109,X
         STA $0105,X
         LDA $0107,X
         STA $0109,X
         LDA $0101,X
         STA $0107,X
         LDA $0108,X
         STA $0104,X
         LDA $0106,X
         STA $0108,X
         TYA 
         STA $0106,X
         PLA 
         TAX 
         PLA 
         PLP 
         RTS 
; 
RESALL:   PLA 
         TAY 
         PLA 
         TAX 
         PLA 
         PLP 
         RTS 
; 
; 
; 

;------------------------------------------
;
;
X_L4034:
;
X_SIOV:
		jmp	$77f
;
;
L_SETVBV:
		lda	$10f9
		beq	L_E46D
L_E461:		lda	DBUFLO+1
		cmp	#$C0			;192
		bcc	L_E46A
		bcs	L_E47A
L_E46A:		jmp	$10f9			; gotta fix this if I am a movable command.com
;
L_E46D:		ldx	#17			; $11
L_E46F:
w9a01:		lda	L_E516,X
		sta	$10f9,X
		dex
		bpl	L_E46F
		bne	L_E461
L_E47A:		lda	DBYTLO
		eor	#$FF
		tax
L_E480:		INX
w9a02:		stx	L_E511
L_E484:		lda	$3D
w9a03:		sta	L_E514
		lda	$3D+1
w9a04:		sta	L_E514+1
		lda	DBUFLO
w9a05:		sta	L_E512
		sec
L_E495:
w9a06:		SBC	L_E511
		sta	$3D
		lda	DBUFLO+1
w9a07:		sta	L_E512+1
		sbc	#0
		sta	$3D+1
L_E4A4:		lda	casetbuf,X
w9a08:		sta	L_E527,X
		inx
		bne	L_E4A4
		lda	DSTATS
		beq	L_E4C7
		bpl	L_E4CD
		bne	L_E4B6
L_E4B6:
w9a09:		LDY	L_E511
L_E4B9:		lda	($3D),Y
		sta	casetbuf,Y
		iny
		bne	L_E4B9
w9a10:		jsr	L_E503
w9a11:		jmp	L_E4DF
;
L_E4C7:
w9a12:		jsr	L_E503
w9a13:		jmp	L_E4DF
;
L_E4CD:
w9a14:		jsr	L_E503
		tya
		tax
w9a15:		ldy	L_E511
L_E4D5:		lda	casetbuf,Y
		sta	($3D),Y
		iny
		bne	L_E4D5
		txa
		tay
L_E4DF:
w9a16:		ldx	L_E512
w9a17:		lda	L_E512+1
		stx	DBUFLO
		sta	DBUFLO+1
w9a18:		lda	L_E514
L_E4EE:		sta	$3D
w9a19:		lda	L_E514+1
		sta	$3D+1
w9a20:		ldx	L_E511
L_E4F8:
w9a21:		lda	L_E527,X
		sta	casetbuf,X
		inx
		bne	L_E4F8
		tya
		rts
;
L_E503:
w9a22:		lda	L_E511
		sta	DBUFLO
		lda	#4
		sta	DBUFLO+1
L_E50E:		jmp	$10f9
;
L_E511:		dc.b	0
L_E512:		dc.w	0
L_E514:		dc.w	0

L_E516:		lda	PORTB
		pha
		ora	#1
		sta	PORTB
		jsr	SIOV
		pla
		sta	PORTB
		rts
;
L_E527:		dc.b	0

L_E528:		lda	(BUFRLO),Y
		sta	$31
		sta	SEROUT
		iny
L_E530:		dc.b	$2C
L_E531:		INC	BUFRLO+1
		dec	bfenlo+1
		bmi	L_E544
L_E537:		lda	(BUFRLO),Y
w9a23:		jsr	L_E639
w9a24:		jsr	L_E5F1
		iny
		bne	L_E537
		beq	L_E531
L_E544:		CPY	BFENLO
		beq	L_E554
		lda	(BUFRLO),Y
w9a25:		jsr	L_E639
w9a26:		jsr	L_E5F1
		iny
w9a27:		jmp	L_E544
;
L_E554:		lda	$31
w9a28:		jsr	L_E639
L_E559:		lda	IRQST
		and	#8
		bne	L_E559
		lda	#$C0
		sta	IRQEN
		ldx	#0
		ldy	#2
w9a29:		jmp	L_E5A7
;
L_E56C:
		lda	#0
		sta	$31
		tay
L_E571:		dc.b	$2C
L_E572:		INC	BUFRLO+1
		dec	bfenlo+1
		bmi	L_E587
L_E578:
w9a30:		jsr	L_E5F9
		bcs	L_E5A3
		sta	(BUFRLO),Y
w9a31:		jsr	L_E5F1
		iny
		bne	L_E578
		beq	L_E572
L_E587:		CPY	BFENLO
		beq	L_E598
w9a32:		jsr	L_E5F9
		bcs	L_E5A3
		sta	(BUFRLO),Y
w9a33:		jsr	L_E5F1
		iny
		bne	L_E587
L_E598:
w9a34:		jsr	L_E5F9
		cmp	$31
		bne	L_E5A1
		clc
		rts
;
L_E5A1:		lda	#143    ;$8F
L_E5A3:		sta	$30
		sec
		rts
;
L_E5A7:
w9a35:		jsr	L_E5D7
w9a36:		jsr	L_E653
L_E5AD:		lda	#$3C			;60 dec
		sta	PBCTL
w9a37:		jsr	L_E5F9
		bcs	L_E5C8
		cmp	#'A'			; $41  ; May need to be 'A'
		beq	L_E5CE
		cmp	#'C'			;$43
		beq	L_E5CE
		cmp	#'E'			;$45
		beq	L_E5C6
		lda	#139			;$8B
		dc.b	$2C
L_E5C6:		lda	#144			;$90
L_E5C8:		sta	$30
		cmp	#139			;$8B
		sec
		rts
;
L_E5CE:		LDY	#0
		ldx	#0
w9a38:		jsr	L_E5D7
		clc
		rts
;
L_E5D7:
		lda	# low $07CF
		sta	$0226
		lda	# high $07CF
		sta	$0226+1
		lda	#0
		sta	STACKP
		lda	#1
		sta	$30
L_E5EA:		STX	$0218+1
		sty	$0218
		rts
;
L_E5F1:
		clc
		adc	$31
		adc	#0
		sta	$31
		rts
;
L_E5F9:		BIT	STACKP
		bmi	L_E635
		lda	#$20
		bit	IRQST
		bpl	L_E622
		bne	L_E5F9
;
;
L_E607:		lda	#$DF
		sta	IRQEN
		lda	#$F8
		sta	IRQEN
		lda	SKSTAT
		sta	SKRES
		bpl	L_E62F
		and	#$20
		beq	L_E632
		lda	SERIN
		clc
		rts
;
L_E622:		lda	#$5F
		sta	IRQEN
		lda	#$F8
		sta	IRQEN
		lda	#128		;$80 user break abort
		dc.b	$2C
L_E62F:		lda	#140		;$8c serial framing error
		dc.b	$2C
L_E632:		lda	#142		;$8e sio serial bus overrun error
		dc.b	$2C
L_E635:		lda	#138		;$8a drive not present
		sec
		rts
;
L_E639:		PHA
L_E63A:		lda	IRQST
		and	#$10
		bne	L_E63A
		lda	#$EF
L_E643:		sta	IRQEN
		lda	#$F8
		sta	IRQEN
		pla
		sta	SEROUT
		rts
;
;
; Just noise being made I think
;
;
L_E650:
		lda	#$23		; 35 dec
		dc.b	$2C
L_E653:		lda	#$13		;19 dec
		sta	SKCTL
		sta	SKRES
		lda	#$28
		sta	AUDCTL
		lda	SOUNDR
		beq	L_E667
		lda	#168
		dc.b	$2C
L_E667:		lda	#160
		sta	AUDC4
L_E66C:		lda	#0
		sta	IRQEN
		lda	#$F8
		sta	IRQEN
		rts
;
;
; sttmot: calculate timout value from dtimlo
;
L_E677:
		lda	DTIMLO
		ror
		ror
		tay
		and	#$3F		; not sure if this is a quick math or not
		tax
		tya
		ror
		and	#$C0		; not sure if this is a quick math or not
		tay
		rts
;
;
;  BEEP BEEP BEEP
; on disk io
;
L_E686:
		lda	POKMSK
		sta	IRQEN
		ldx	#6
		lda	#0
L_E68F:		sta	AUDC1,X
		dex
		dex
		bpl	L_E68F
L_E696:		RTS
;
;
;  Drive Handler table to support 8 drives
;  Hope this is it
;
;
L_E697:
;  this had a byte added for the HISpeed Status of drv 9
		dc.b	0,0,0,0
		dc.b	0,0,0,0
;		dc.b	0				;leaving this out for the time being
;
;
L_E69F:		ldx	# low L_E69F-L_E697 ; Should be 8
;
L_E6A1:		lda	DCOMND,X
		pha
		dex
		bpl	L_E6A1
;
; return high speed command in
; spartados
;
		lda	#'?'     ;$3F
		sta	DCOMND
		ldx	#1
		stx	DBUFLO
		stx	DBYTLO
		stx	DTIMLO
		dex
		stx	DBUFLO+1
		stx	DBYTLO+1
		lda	#$40
		sta	DSTATS
		lda	#4
		sta	DAUX1
w9a39:		jsr	L_E484
		bmi	L_E6D6
		lda	NGFLAG
		ldy	DUNIT
w9a40:		sta	L_E697-1,Y
L_E6D6:		ldx	#0
L_E6D8:		PLA
		sta	DCOMND,X
		inx
		cpx	#low L_E69F-L_E697+1		; $09
		bne	L_E6D8
		rts
;
L_E6E2:		ldx	#low L_E69F-L_E697		; Should be 8
		lda	#$FF
L_E6E6:
w9a41:		sta	L_E697-1,X
		dex
		bne	L_E6E6
		rts
;
;
LE_RAM_END:
;
;----------------------------
; HI-Speed sio handler
;dissambled by Stephen J. Carden  
; 12/25/1995
;----------------------------
;
S_L4034:
;		.org	$E459
;
S_SIOV:
		jmp	$77f		;  S_L077F
S_SETVBV:
		lda	#0
		sta	CASFLG
		lda	DDEVIC
		cmp	#$31		; value for disk#1
		bne	S_LE482
		ldy	DUNIT
w9b01:		lda	S_LE696,Y
		bpl	S_LE478
		lda	#40		;$28 this may be something
w9b02:		sta	S_LE696,Y
w9b03:		jsr	S_LE69F
S_LE478:	LDY	DUNIT
w9b04:		ldx	S_LE696,Y
		lda	#$0E
S_LE480:	BNE	S_LE486
S_LE482:	LDA	#$0E
S_LE484:	LDX	#$28
S_LE486:	STA	TSTAT
		stx	AUDF3
		lda	#0
		sta	AUDF4
		clc
		lda	DDEVIC
S_LE495:	ADC	DUNIT
		adc	#$FF
		sta	CDEVIC
		lda	DCOMND
		sta	CCOMND
		lda	DAUX1
		sta	CAUX1
		lda	DAUX1+1
		sta	CAUX1+1
S_LE4AF:	SEI
		lda	#2
		sta	DRETRY
S_LE4B5:	LDA	TSTAT
		sta	CRETRY
S_LE4BB:	LDA	#low CDEVIC ;$3A
		sta	BUFRLO
		lda	#high CDEVIC ;2
		sta	BUFRLO+1
		lda	#4
		sta	BFENLO
		lda	#0
		sta	bfenlo+1
;
;
;
; Hummm I wonder what $34 stored into $d303 is doing
;
		lda	#$34
		sta	PBCTL
w9b05:		jsr	S_LE51E
S_LE4D3:	BCC	S_LE4DC
S_LE4D5:	DEC	CRETRY
		bne	S_LE4BB
		beq	S_LE4FB
S_LE4DC:
w9b06:		JSR	S_LE509
		bit	DSTATS
		bpl	S_LE4E9
w9b07:		jsr	S_LE51E
		bcs	S_LE4D5
S_LE4E9:
w9b08:		JSR	S_LE677
w9b09:		jsr	S_LE5A7
		bcs	S_LE4FB
		bit	DSTATS
		BVC	S_LE500
w9b10:		jsr	S_LE56C
		bcc	S_LE500
S_LE4FB:	DEC	DRETRY
		bne	S_LE4B5
S_LE500:
w9b11:		JSR	S_LE686
		cli
		lda	#0
		ldy	$30
		rts
;
S_LE509:
		lda	DBUFLO
		sta	BUFRLO
S_LE50E:	LDA	DBUFLO+1
		sta	BUFRLO+1
		lda	DBYTLO
		sta	BFENLO
		lda	DBYTLO+1
		sta	bfenlo+1
		rts
;
S_LE51E:
		ldx	#$FF
S_LE520:	DEX
		bne	S_LE520
w9b12:		jsr	S_LE650
		ldy	#0
		lda	(BUFRLO),Y
		sta	$31
		sta	SEROUT
		iny
		dc.b	$2C
S_LE531:	INC	BUFRLO+1
;
		dec	bfenlo+1
		bmi	S_LE544
S_LE537:	LDA	(BUFRLO),Y
w9b13:		jsr	S_LE639
w9b14:		jsr	S_LE5F1
		iny
		bne	S_LE537
		beq	S_LE531
S_LE544:	CPY	BFENLO
		beq	S_LE554
		lda	(BUFRLO),Y
w9b15:		jsr	S_LE639
w9b16:		jsr	S_LE5F1
		iny
w9b17:		jmp	S_LE544
;
S_LE554:	LDA	$31
w9b18:		jsr	S_LE639
S_LE559:	LDA	IRQST
		and	#8
		bne	S_LE559
		lda	#$C0
		sta	IRQEN
		ldx	#0
		ldy	#2
w9b19:		jmp	S_LE5A7
;
S_LE56C:
		lda	#0
		sta	$31
		tay
		dc.b	$2C
S_LE572:	INC	BUFRLO+1
S_LE574:	DEC	bfenlo+1
		bmi	S_LE587
S_LE578:
w9b20:		JSR	S_LE5F9
		bcs	S_LE5A3
		sta	(BUFRLO),Y
w9b21:		jsr	S_LE5F1
		iny
		bne	S_LE578
		beq	S_LE572
S_LE587:	CPY	BFENLO
		beq	S_LE598
w9b22:		jsr	S_LE5F9
		bcs	S_LE5A3
		sta	(BUFRLO),Y
w9b23:		jsr	S_LE5F1
		iny
		bne	S_LE587
S_LE598:
w9b24:		JSR	S_LE5F9
		cmp	$31
		bne	S_LE5A1
		clc
		rts
;
S_LE5A1:	LDA	#143 ; $8F
S_LE5A3:	STA	$30
		sec
		rts
;
S_LE5A7:
w9b25:		jsr	S_LE5D7
w9b26:		jsr	S_LE653
S_LE5AD:	LDA	#60			;$3C
		sta	PBCTL
w9b27:		jsr	S_LE5F9
		bcs	S_LE5C8
		cmp	#'A'			; $41
		beq	S_LE5CE
		cmp	#'C'			; $43
		beq	S_LE5CE
		cmp	#'E'			; $45
		beq	S_LE5C6
		lda	#139			; $8B
		dc.b	$2C
S_LE5C6:	LDA	#144			; $90
S_LE5C8:	STA	$30
		cmp	#139			; $8B
		sec
		rts
;
S_LE5CE:	LDY	#0
		ldx	#0
w9b28:		jsr	S_LE5D7
		clc
		rts
;
S_LE5D7:
		lda	# low $07CF
		sta	$0226
		lda	# high $07CF
		sta	$0226+1
		lda	#0
		sta	STACKP
		lda	#1
		sta	$30
S_LE5EA:	STX	$0218+1
		sty	$0218
		rts
;
S_LE5F1:
		clc
		adc	$31
		adc	#0
		sta	$31
		rts
;
S_LE5F9:	BIT	STACKP
		bmi	S_LE635
		lda	#$20
		bit	IRQST
		bpl	S_LE622
S_LE605:	BNE	S_LE5F9
S_LE607:	LDA	#$DF
		sta	IRQEN
		lda	#$F8
		sta	IRQEN
		lda	SKSTAT
		sta	SKRES
		bpl	S_LE62F			;   420A
		and	#$20
		beq	S_LE632			;  420D
		lda	SERIN
		clc
		rts
;
S_LE622:	LDA	#$5F
		sta	IRQEN
		lda	#$F8
		sta	IRQEN
		lda	#128			;$80 user break abort
		dc.b	$2C
S_LE62F:	LDA	#140			; $8c serial framing error
		dc.b	$2C
S_LE632:	LDA	#142			; $8e sio serial bus overrun error
		dc.b	$2C
S_LE635:	LDA	#138			; $8a drive not present
		sec
		rts
;
S_LE639:
		pha
S_LE63A:	LDA	IRQST
		and	#$10
		bne	S_LE63A
		lda	#$EF
S_LE643:	STA	IRQEN
		lda	#$F8
		sta	IRQEN
		pla
		sta	SEROUT
		rts
;
S_LE650:	LDA	#$23
;
		dc.b	$2C
S_LE653:	LDA	#$13
;
		sta	SKCTL
		sta	SKRES
		lda	#$28
		sta	AUDCTL
		lda	SOUNDR
		beq	S_LE667
		lda	#168    ;$A8
		dc.b	$2C
S_LE667:	LDA	#160    ;$A0
;
		sta	AUDC4
S_LE66C:	LDA	#0
		sta	IRQEN
		lda	#$F8
		sta	IRQEN
		rts
;
S_LE677:
		lda	DTIMLO
		ror
		ror
		tay
		and	#$3F ; I have no Idea
		tax
		tya
		ror
		and	#$C0 ; I have no Idea
		tay
		rts
;
S_LE686:
		lda	POKMSK
		sta	IRQEN
		ldx	#6
		lda	#0
S_LE68F:	STA	AUDC1,X
		dex
		dex
		bpl	S_LE68F
S_LE696:	RTS
;
S_LE697:
;
;This needs an extra byte to status all 9 Drives
		dc.b	0,0,0,0
		dc.b	0,0,0,0
;		dc.b	0				; leaving this out for the time being
;
S_LE69F:	LDX	# low S_LE69F-S_LE697
S_LE6A1:	LDA	DCOMND,X
		pha
		dex
		bpl	S_LE6A1
;
; return high speed command in USDoubler Drives
; 1 byte return UsDoubler = 10
;
;
;
		lda	#'?'
		sta	DCOMND
		ldx	#1
		stx	DBUFLO
		stx	DBYTLO
		stx	DTIMLO
		dex
		stx	DBUFLO+1
		stx	DBYTLO+1
		lda	#$40
		sta	DSTATS
		lda	#4
		sta	DAUX1
w9b29:		jsr	S_LE484
		bmi	S_LE6D6
		lda	NGFLAG
		ldy	DUNIT
w9b30:		sta	S_LE697-1,Y
S_LE6D6:	LDX	#0
S_LE6D8:	PLA
		sta	DCOMND,X
		inx
		cpx	# low S_LE69F-S_LE697+1
		bne	S_LE6D8
		rts
;
S_LE6E2:
		ldx	# low S_LE69F-S_LE697
		lda	#$FF
S_LE6E6:
w9b31:		STA	S_LE696,X
		dex
		bne	S_LE6E6
		rts
;
SE_RAM_END:	ds.b	0
;
win_end:	ds.b	0
;
