;------------------------------------------------------------------------
;
;		Copyright 2010 Intergraded Logic Systems
;                  Source Code is Copyright Stephen J. Carden
;
;
;			Please do not share this source!
;------------------------------------------------------------------------
;       os_menu.com  used to program the Smartos for real.dos 
;
;------------------------------------------------------------------------
;                         Real.dos os_menu.COM
;			This program is to replace
;		      		os_menu.com
;
;	Code History.     Init design,   10/30/1998
;			  last updated   11/05/2005	sjc
;			reformatted source 4/05/2010	sjc
;			update os detection 06/04/2010	sjc
;
;
;Updated the screen Print Utility so it will work with the exp-80
; This change will also help "Print P:"		8/17/2012	sjc
;
;
;Also added code for Control+1 pause of screen to the high speed screen
;handling.		8/24/2012	sjc
; 
;
;
;Added code so this file cannot run on the AtariWin800 Emulator
;		8/24/2012	sjc
;;
;
;
;
;       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;------------------------------------------------------------------------
; 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,"Os_menu.com ",$9b
			.endm

;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; File revision history. Version Number in hex
;
file_ver:		equ   $18
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; 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   15
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; 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
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



;
;
on:			equ	$01
off:			equ	$00
;
;
;-----------------------------
;
cart_a:			equ	$a000
cart_l:			equ	$1fff
os_l:			equ	$4000
selftest:		equ	$e471
reset:			equ	$e474
cold_start:		equ	$e477
memory:			equ	$4000
os:			equ	$c000
control:		equ	$d380
boot.:			equ	$09



kbd:			equ	$30

i.in_ptr:		equ	$a0         
i.s_ptr:		equ	$a2       
i.d_ptr:		equ	$a4       
i.fn_ptr:		equ	$a6       
i.pr_ptr:		equ	$a8       

i.crc_ptr:		equ	$8b
i.c_ptr:		equ	$9e
i.st_ptr:		equ	$cc
i.v_ptr:		equ	$ca
;
;
os_rom:			equ	$40
os_ram:			equ	$80
os_ram1:		equ	$01
os_write:		equ	$20
;
;-----------------Macros---------------------------
;
show_hex_word         .macro	field
			lda	%1
			ldx	%1+1
			jsr	h_card
			.ENDM
;
;----------------------end of macros---------------------------
;

			.include	equates
			.include	globals
			.include	macros

			.org	$2300
;
win_start:
header_info:
			.include	header			; this reads info out of the header and displays to screen

A_start:
			jsr	mem_test
			jmp	start


parm_1:
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0

parm_2:
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
instr:
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
in_str:
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
;
;

;----------------------------------
;    ERROR NUMBER 
;this take's the value of the a reg
;and put a hex number to the screen
;----------------------------------
;
h_cardd:		dc.b	$00
;
; print a hex word value
; low byte in a reg x is high byte
;
h_card:			sta	h_cardd
			txa
			jsr	drive_error
			lda	h_cardd
			jsr	drive_error
			rts
;
;
drive_error:		pha
			lsr
			lsr
			lsr
			lsr
			jsr	.a
			pla
			and	#$0f
.a:			cmp	#$0a
			bcs	.b
			ora	#$30
			bne	.c
.b:			adc	#$36
.c:			jsr	sprint
			rts
;
;
;-------------
;time date off
;-------------
;
;
td:
			lda	portb
			pha
			and	#$fe
			sta	portb
			jsr	vtdon
			pla
			sta	portb
			rts
;

;
pr_byte:
			ldx	#$00
pr_card:
			sta	fr0
			stx	fr0+1
			lda	#$00
			sta	cix
			jsr	ifp
			jsr	fasc
			ldy	#$00
.a:
			lda	(inbuff),y
			php
			and	#$7f
			iny
			jsr	echo
			plp
			bpl	.a
			rts
;
;---------------------------
;this one make's a nice tone
;---------------------------
bell:
			sta	bell_m3
			sty	bell_m3+1
			stx	bell_m3+2
			ldy	#$af
			lda	#$14
			sta	$d200
bell_m1:		sty	$d201
			lda	#$00
			sta	$14
bell_m2:		lda	$14
			cmp	#$02
			bcc	bell_m2
			dey
			cpy	#$a0
			bcs	bell_m1
			lda	bell_m3
			ldy	bell_m3+1
			ldx	bell_m3+2
			rts
bell_m3:		dc.b	$00,$00,$00
;
;----------------------
; BIT LOGIC LOAD ACC   
; LOAD Y REG WITH BIT #
;----------------------
check_bit:
			sta	check_hold
			sty	check_hold+1
			ldy	#$00
			lda	#$00
check1:			sta	check_line,y
			iny
			cpy	#$08
			bcc	check1
			lda	check_hold
			clc
			asl
			bcc	c_bit_1
			ldy	#$01
			sty	check_line+7
			clc
c_bit_1:
			asl
			bcc	c_bit_2
			ldy	#$01
			sty	check_line+6
			clc
c_bit_2:
			asl
			bcc	c_bit_3
			ldy	#$01
			sty	check_line+5
			clc
c_bit_3:
			asl
			bcc	c_bit_4
			ldy	#$01
			sty	check_line+4
			clc
c_bit_4:
			asl
			bcc	c_bit_5
			ldy	#$01
			sty	check_line+3
			clc
c_bit_5:
			asl
			bcc	c_bit_6
			ldy	#$01
			sty	check_line+2
			clc
c_bit_6:
			asl
			bcc	c_bit_7
			ldy	#$01
			sty	check_line+1
			clc
c_bit_7:
			cmp	#$00
			beq	c_bit_8
			ldy	#$01
			sty	check_line
			clc
c_bit_8:
			clc
			ldy	check_hold+1
			lda	check_line,y
			cmp	#$01
			bne	c_bit_9
			sec
			rts
c_bit_9:		clc
			rts
check_hold:		dc.b	0,0
check_line:		dc.b	0,0,0,0,0,0,0,0



;-----------------------------
install_dli:
			lda	# low dli_1
			sta	$0200
			lda	# high dli_1
			sta	$0201
			lda	#$c0
			sta	$d40e
			rts

;dli_test:		dc.b	0,0,0,0


dli_1:
			pha
			txa
			pha
			tya
			pha

correct_dli_1:
			cmp	#23
			beq	correct_dli_2
			cmp	#28
			beq	correct_dli_3
			cmp	#45
			beq	correct_dli_4
			lda	#$80
			sta	$d40a
			sta	$d018
			lda	# low dli_2
			sta	$0200
			lda	# high dli_2
			sta	$0201
			pla
			tya
			pla
			tax
			pla
			rti
;
dli_2:
			pha
			txa
			pha
			tya
			pha

correct_dli_2:
;			lda	vcount
;			sta	dli_test+1

			cmp	#19
			beq	correct_dli_1
			cmp	#28
			beq	correct_dli_3
			cmp	#45
			beq	correct_dli_4
			lda	#$40
			sta	$d018
			lda	# low dli_3
			sta	$0200
			lda	# high dli_3
			sta	$0201
			lda	#$00
			sta	in_vbi
			pla
			tay
			pla
			tax
			pla
			rti
;
dli_3:
			pha
			txa
			pha
			tya
			pha

correct_dli_3:

			cmp	#19
			beq	correct_dli_1
			cmp	#23
			beq	correct_dli_2
			cmp	#45
			beq	correct_dli_4

			lda	#$80
			sta	$d018
			lda	# low dli_4
			sta	$0200
			lda	# high dli_4
			sta	$0201
			pla
			tya
			pla
			txa
			pla
			rti
;
;
dli_4:
			pha
			txa
			pha
			tya
			pha

correct_dli_4:
;			lda	vcount
;			sta	dli_test+3

			cmp	#19
			beq	correct_dli_1
			cmp	#23
			beq	correct_dli_2
			cmp	#28
			beq	correct_dli_3

			lda	#$40
			sta	$d018
			lda	# low dli_1
			sta	$0200
			lda	# high dli_1
			sta	$0201
			pla
			tya
			pla
			tax
			pla
			rti
;
;
d_list:			dc.b	$70,$70,$70
			dc.b	$42+$80
			dc.w	my_sjc			;      PROGRAM_NAME
			dc.b	$82
			dc.b	$42
			dc.w	program_name
			dc.b	$80
			dc.b	$42
			dc.w	rw_screen
			dc.b	2,2,2
			dc.b	0,$80
			dc.b	$42
fixup:
d_l_mem:		dc.w	0
			dc.b	2,2,2,2,2,2,2,2
			dc.b	2,2,2,2,2,2,2,2
			dc.b	$41
			dc.w	d_list
;
;
break_int:
			mea	break_it,$0206
			rts
;
break_it:
			jsr	printsi
			dc.b	$9b,"This is ODD. a BRK instruction found",$9B,-1
			jsr	more
			jmp	main_menu
;
start:
			jsr	break_int
			jsr	install_dli
			lda	#$02
			sta	$52
			ldy	#off
			jsr	td
			lda	#$00
			sta	invflg
			sta	shflok
			jsr	test_os
			jsr	test_smartos
			jsr	init_screen
;
			jsr	test_smartos
			jsr	do_all_crc
			jsr	pause
			jsr	statbox
;
			lda	consol
			cmp	#$05			; SELECT KEY
			beq	lisa
			jmp	main_menu
;
lisa:			jsr	printsi
			dc.b	$9b,$9b," Start $",-1
			show_hex_word	prg_start
			jsr	printsi
			dc.b	"   End $",-1
			show_hex_word	prg_end
			jsr	printsi
			dc.b	" Length $",-1
			show_hex_word	prg_length
			jsr	printsi
			dc.b	$9b,$9b," Start $",-1
			show_hex_word	prg_s_start
			jsr	printsi
			dc.b	"   End $",-1
			show_hex_word	prg_s_end
			jsr	printsi
			dc.b	" Length $",-1
			show_hex_word	prg_s_length
			jsr	printsi
			dc.b	$9b,$9b,-1
;
			jsr	pause
;
main_menu:
;
			mea	os_name,i.s_ptr
			mea	parm_1,i.d_ptr
			jsr	move_str
			mea	parm_1,i.fn_ptr
			jsr	file_stat
;
			jsr	statbox
			jsr	printsi
			dc.b	$7d,-1
			lda	which_menu
			cmp	#$00
			beq	A_.
			jmp	screen_2
A_.:			jmp	screen_1
screen_2:
			jsr	printsi
;
			dc.b	$9b
			dc.b	<+128>,"[H]"
			dc.b	" Install Hex String into memory",$9B
			dc.b	<+128>,"[D]"
			dc.b	"eposit a Single Hex byte to memory",$9B
			dc.b	<+128>,"[R]"
			dc.b	" Purge all of the ramdisk",$9B
			dc.b	<+128>,"[P]"
			dc.b	"rogram SMART OS",$9B
			dc.b	<+128>,"[W]"
			dc.b	" Toggle SMART OS write mode",$9B
			dc.b	<+128>,"[O]"
			dc.b	" DOS Functions!",$9B
			dc.b	<+128>,"[Q]"
			dc.b	" Inspect a bank of Ram!",$9B
			dc.b	<+128>,"[M]"
			dc.b	"ake Cartridge in com file!",$9B
			dc.b	<+128>,"[Z]"
			dc.b	" Bank switch OS",$9B
;
			dc.b	-1
			jmp	work_it
;
screen_1:
;
			jsr	frankie
			jsr	printsi
			dc.b	<+128>,"[4]"
			dc.b	" Enter comment line(S)!",$9B
			dc.b	<+128>,"[5]"
			dc.b	" Create Smart OS Loadable file!",$9B
			dc.b	<+128>,"[6]"
			dc.b	" Change Control ddress!",$9B
			dc.b	<+128>,"[I]"
			dc.b	"nspect HEX address",$9B
			dc.b	<+128>,"[L]"
			dc.b	"oad E-Prom File!",$9B
			dc.b	<+128>,"[S]"
			dc.b	"ave E-Prom File!",$9B
			dc.b	<+128>,"[C]"
			dc.b	"hecksum Test on OS Ram!",$9B
			dc.b	<+128>,"[X]"
			dc.b	" Exit program",$9B
			dc.b	<+128>,"[F]"
			dc.b	"ile name Change",$9B
			dc.b	<+128>,"[E]"
			dc.b	"rase buffer",$9B
			dc.b	-1
;
work_it:
			jsr	printsi
			dc.b	<+128>,"[SPACE]"
			dc.b	" Toggles Menu",$9B
			dc.b	$9b," Command "
			dc.b	-1
			mea	key_table,i.s_ptr
			jsr	my_key
			jsr	execute
			jmp	main_menu
;
which_menu:		dc.b	0
;
key_table:
			dc.b	$7d
			dc.w	reset
			dc.b	"E"
			dc.w	bank_purge
			dc.b	"X"
			dc.w	s_exit
			dc.b	$1b
			dc.w	s_exit
			dc.b	"C"
			dc.w	s_csum
			dc.b	"S"
			dc.w	steve_os
			dc.b	"L"
			dc.w	s_load
			dc.b	"5"
			dc.w	s_create
			dc.b	"1"
			dc.w	s_rom
			dc.b	"2"
			dc.w	s_ram
			dc.b	"3"
			dc.w	s_ram1
			dc.b	"F"
			dc.w	s_file
			dc.b	"M"
			dc.w	read_cart
			dc.b	"5"   ;
			dc.w	s_address
			dc.b	"I"
			dc.w	s_inspect
			dc.b	"*"
			dc.w	s_inspect
			dc.b	"D"
			dc.w	s_put
			dc.b	"4"   ;
			dc.w	s_memo
			dc.b	"H"
			dc.w	my_put
			dc.b	"R"
			dc.w	bank_mem
			dc.b	"P"
			dc.w	s_program
			dc.b	"O"
			dc.w	t_dos
			dc.b	" "
			dc.w	s_page
			dc.b	"Q"
			dc.w	s_ram_look
			dc.b	"V"
			dc.w	s_brk
			dc.b	"W"
			dc.w	s_write_m
			dc.b	"Z"
			dc.w	program_rom
			dc.b	0
			dc.w	s_error
;
s_brk:
			brk
;
s_write_m:
			lda	rw_control
			eor	#os_write
			sta	rw_control
			jmp	control_line
;
s_page:
			lda	which_menu
			cmp	#$00
			beq	l_gh
			lda	#$00
			sta	which_menu
			rts
l_gh:
			lda	#$01
			sta	which_menu
			rts
;


t_dos:
;          pop_word  i_sc_hold_mem,savmsc
;          pop_word  i_sc_hold_dlist,sdlstl
			jmp	s_dos



s_csum:
			jsr	statbox
			jsr	printsi
			dc.b	$7d,$9b,-1

;debug code			
;			lda	dli_test
;			jsr	pr_byte
;			lda	#$20
;			jsr	echo
;			lda	dli_test+1
;			jsr	pr_byte
;			lda	#$20
;			jsr	echo
;			lda	dli_test+2
;			jsr	pr_byte
;			lda	#$20
;			jsr	echo
;			lda	dli_test+3
;			jsr	pr_byte
;			lda	#$20
;			jsr	echo
;end of debug


			jsr	printsi
			dc.b	$9b,$9b
			dc.b	" Checksum menu!",$9B,$9B
			dc.b	-1
			jsr	frankie
			jsr	printsi
;
			dc.b	<+128>,"[4]"
			dc.b	" Checksum test RAM OS",$9B
			dc.b	<+128>,"[5]"
			dc.b	" Checksum test Memory",$9B
			dc.b	<+128>,"[6]"
			dc.b	" Checksum test Rom OS",$9B
			dc.b	<+128>,"[M]"
			dc.b	"ain menu!",$9B
			dc.b	$9b,$9b," Selection ",-1
			mea	m_crc_table,i.s_ptr
			jsr	my_key
			jsr	execute
			jmp	s_csum
;
;
m_crc_table:
			dc.b	"4"
			dc.w	crc_rom
			dc.b	"5"
			dc.w	crc_ram
			dc.b	"6"
			dc.w	crc_rom_os
			dc.b	"1"
			dc.w	s_rom
			dc.b	"2"
			dc.w	s_ram
			dc.b	"3"
			dc.w	s_ram1
			dc.b	"M"
			dc.w	main_menu
			dc.b	"X"
			dc.w	s_exit
			dc.b	$1b
			dc.w	s_exit
			dc.b	"*"
			dc.w	s_inspect
			dc.b	"I"
			dc.w	s_inspect
			dc.b	"H"
			dc.w	my_put
			dc.b	"D"
			dc.w	s_put
			dc.b	$7d
			dc.w	reset
			dc.b	0
			dc.w	s_done
;
;
crc_rom_os:
			jsr	s_rom
			jmp	crc_ram
;
;
s_exit:
			pla
			pla
			lda	#$7d
			jsr	echo
			lda	#$ff
			sta	ch
			jsr	exit_screen
			lda	$0700
			cmp	#'R'     ; SpartaDos
			beq	ss_exit
			lda	$0701
			cmp	#$40
			bcc	ss_exit
			lda	#$ff
			sta	$0244
ss_exit:		jmp	reset
;
;
s_load:
			ldx	#disk_2
			jsr	close
			mea	os_name,i.fn_ptr
			ldx	#disk_2
			jsr	bload
			ldx	#disk_2
			jsr	close
;
s_done:			rts
;
s_ram_look:
			jsr	printsi
			dc.b	$7d
			dc.b	$9b,$9b,"Read Which Bank Of ram 1 to ",-1
			lda	total_banks
			jsr	pr_byte
			jsr	printsi
			dc.b	$9b,"Enter The Bank You wish to inspect!",$9B
			dc.b	" 0 = Main Memory",$9B,$9B
			dc.b	"Bank ?",-1
			jsr	get_byte
			cmp	total_banks
			beq	kio
			bpl	s_ram_look
			cmp	#$00
			beq	hyu
kio:			tay
			sta	current_ram_bank
			lda	total_banks,y
			eor	xor_byte
			sta	portb
			rts
hyu:			sta	current_ram_bank
			lda	ils_hold_d301
			sta	portb
			rts
;
s_create:
			lda	#$01
			sta	rw_mode
			jsr	make_os
			lda	#$00
			sta	rw_mode
			rts
;
s_ram:
			jsr	bank_purge
			jsr	my_wait
			php
			lda	nmien
			pha
			lda	#$00
			sta	nmien
			sei
			jsr	load_2
			lda	#os_ram
			jsr	control_line
			jsr	rom_to_ram
			lda	smos_data
			jsr	control_line
			pla
			sta	nmien
			plp
			jsr	restore_2
			cli
			jsr	my_wait
			rts
;
s_rom:
			jsr	bank_purge
			jsr	my_wait
			php
			lda	nmien
			pha
			lda	#$00
			sta	nmien
			sei
			jsr	load_2
			lda	#os_rom
			jsr	control_line
			jsr	rom_to_ram
			lda	smos_data
			jsr	control_line
			pla
			sta	nmien
			plp
			jsr	restore_2
			cli
			jsr	my_wait
			rts
;
;
s_error:
			jsr	printsi
			dc.b	$9b,$9b," That Key not used!",$9B,-1
			jmp	pause
;
s_file:
			jsr	printsi
			dc.b	$9b,$9b," Enter Filename >",-1
			jsr	get_str
			dc.w	parm_1
			dc.b	38,0,1
			mea	parm_1,i.s_ptr
			jsr	upstring
			mea	parm_1,i.s_ptr
			mea	os_name,i.d_ptr
			jsr	toascii
			jmp	cr_lf
;
s_address:
			lda	#'0'
			sta	sss
			sta	sss+1
			sta	sss+2
			sta	sss+3
			jsr	printsi
			dc.b	$9b,$9b," Enter Hex $",-1
			jsr	get_str
			dc.w	a.cnt_point
			dc.b	4,0,1
			mea	a.cnt_point,i.s_ptr
			jsr	upstring
			mea	sss,i.d_ptr
			jsr	toascii
			jsr	steve_pack
			pop_word	sss_data,store2
			pop_word	sss_data,rw_line
			jsr	test_os
			jsr	test_smartos
			jsr	init_screen
			rts
;
s_inspect:
			lda	#'0'
			sta	sss
			sta	sss+1
			sta	sss+2
			sta	sss+3
			jsr	printsi
			dc.b	$9b,$9b," Enter Hex $",-1
			jsr	get_str
			dc.w	parm_1
			dc.b	4,0,1
			mea	parm_1,i.s_ptr
			jsr	upstring
			mea	sss,i.d_ptr
			jsr	toascii
			jsr	steve_pack
			pop_word	sss_data,store2
			rts
;
s_put:
			lda	#'0'
			sta	sss+1
			sta	sss+2
			sta	sss+3
			jsr	printsi
			dc.b	$9b,$9b," Enter Hex Byte $",-1
			jsr	get_str
			dc.w	parm_1
			dc.b	2,0,1
			mea	parm_1,i.s_ptr
			jsr	upstring
			mea	sss,i.d_ptr
			jsr	toascii
			jsr	steve_pack
			lda	store2
			sta	dun+1
			lda	store2+1
			sta	dun+2
			ldy	#$00
			lda	sss_data+1
dun:			sta	$ffff,y
			rts
;
s_memo:
			jsr	printsi
			dc.b	$7d,$9b,$9b,$9b
			dc.b	$9b,$9b," Enter your two line coments",$9B
			dc.b	"         111111111122222222223333333",$9B
			dc.b	"123456789012345678901234567890123456",$9B,-1
			jsr	get_str
			dc.w	memo1
			dc.b	36,0,1
			jsr	cr_lf
			jsr	get_str
			dc.w	memo2
			dc.b	36,0,1
			jsr	cr_lf
			rts
;
my_put:
			jsr	printsi
			dc.b	$9b,$9b," Enter Hex Byte string",$9B,"  $",-1
			jsr	get_str
			dc.w	parm_1
			dc.b	16,0,1
			mea	parm_1,i.s_ptr
			jsr	upstring
			jsr	steve_byte
			lda	store2
			sta	pun+1
			lda	store2+1
			sta	pun+2
			ldy	#$00
xyz:
			lda	zzz_data,y
pun:			sta	$ffff,y
			iny
			cpy	zzz_x
			bne	xyz
			rts
;
my_key:
			lda	brkkey
			cmp	#$00
			bne	_.a
			lda	#$80
			sta	brkkey
			jsr	bbmenu
			lda	#$ff
			sta	ch
_.a:
			lda	consol
			cmp	#$05
			beq	..select
			cmp	#$06
			beq	..start
			cmp	#$03
			beq	..option
			cmp	#$00
			beq	..restart
			lda	helpfg
			cmp	#$00
			bne	..help
			lda	ch
			cmp	#$ff
			beq	my_key
			jmp	get_key
			rts
;
..select:		jsr	..pugkey
			rts
..start:		jsr	..pugkey
			rts
..option:		jsr	..pugkey
			rts
..restart:		lda	#$ff
			sta	$0244
			jmp	$e474
..help:			lda	#$00
			sta	helpfg
			rts
..pugkey:
			lda	#$ff
			sta	ch
			rts
;
s_ram1:
			jsr	bank_purge
			jsr	my_wait
			php
			lda	nmien
			pha
			lda	#$00
			sta	nmien
			sei
			jsr	load_2
			lda	#os_ram1
			jsr	control_line
			jsr	rom_to_ram
			lda	smos_data
			jsr	control_line
			pla
			sta	nmien
			plp
			jsr	restore_2
			cli
			jsr	my_wait
			rts
;
s_program:
			jsr	printsi
			dc.b	$7d,$9b,$9b,$9b
			dc.b	" SMART OS program menu!",$9B,$9B
			dc.b	" "
			dc.b	<+128>,"[1]"
			dc.b	" Program boot ram bank",$9B
			dc.b	" "
			dc.b	<+128>,"[2]"
			dc.b	" Program Aux Ram Bank",$9B
			dc.b	" "
			dc.b	<+128>,"[M]"
			dc.b	"ain menu!",$9B
			dc.b	$9b,$9b," Selection ",-1
			mea	m_pgm_table,i.s_ptr
			jsr	my_key
			jsr	execute
			jmp	s_program
;
m_pgm_table:
			dc.b	"1"
			dc.w	pgm_ram
			dc.b	"2"
			dc.w	pgm_ram1
			dc.b	"M"
			dc.w	main_menu
			dc.b	"X"
			dc.w	s_exit
			dc.b	$1b
			dc.w	s_exit
			dc.b	"*"
			dc.w	s_inspect
			dc.b	"I"
			dc.w	s_inspect
			dc.b	"H"
			dc.w	my_put
			dc.b	"D"
			dc.w	s_put
			dc.b	$7d
			dc.w	reset
			dc.b	0
			dc.w	s_done
;
pgm_ram:
			lda	#os_ram
			sta	rw_control
			jmp	ram_to_rom
;
pgm_ram1:
			lda	rw_control
			sta	pgm_ram1_d
			lda	#os_ram1
			sta	rw_control
			jsr	ram_to_rom
			lda	pgm_ram1_d
			sta	rw_control
			jmp	control_line
;
pgm_ram1_d:		dc.b	0
;
frankie:		jsr	printsi
			dc.b	$9b
			dc.b	<+128>,"[1]"
			dc.b	" Read OS ROM into Memory!",$9B
			dc.b	<+128>,"[2]"
			dc.b	" Read OS Ram into Memory!",$9B
			dc.b	<+128>,"[3]"
			dc.b	" Read OS Ram 1 into Memory!",$9B
			dc.b	-1
			rts
;
;
program_rom:
			jsr	statbox
			jsr	printsi
			dc.b	$7d,$9b
			dc.b	" OS SWAP Menu",$9B,$9B,$9B
			dc.b	<+128>,"[1]"
			dc.b	" Goto Rom OS",$9B
			dc.b	<+128>,"[2]"
			dc.b	" Goto Boot Ram OS",$9B
			dc.b	<+128>,"[3]"
			dc.b	" Goto aux Ram OS",$9B
			dc.b	<+128>,"[M]"
			dc.b	" Main Menu",$9B
			dc.b	$9b,$9b," Enter Your Selection! ",-1
;
;
			mea	m_rom_table,i.s_ptr
			jsr	my_key
			jsr	execute
			jmp	program_rom
;
m_rom_table:
			dc.b	"1"
			dc.w	do_rom
			dc.b	"2"
			dc.w	do_ram
			dc.b	"3"
			dc.w	in_ram
			dc.b	"M"
			dc.w	main_menu
			dc.b	"X"
			dc.w	s_exit
			dc.b	$1b
			dc.w	s_exit
			dc.b	"*"
			dc.w	s_inspect
			dc.b	"I"
			dc.w	s_inspect
			dc.b	"H"
			dc.w	my_put
			dc.b	"D"
			dc.w	s_put
			dc.b	$7d
			dc.w	reset
			dc.b	0
			dc.w	s_done
;
;
do_rom:
			ldy	#0
in_rom:			lda	current_os,y
			cmp	rom_os,y
			bne	cannot
			iny
			cpy	#4
			bne	in_rom
			lda	#os_rom
			sta	rw_control
			sta	smos_data ; ADDED
			jsr	control_line
			mea	smosrom,sm_cfg
not_rom:		rts
;
in_ram:
			ldy	#$00
in_ram1:		lda	current_os,y
			cmp	ram1_os,y
			bne	cannot
			iny
			cpy	#4
			bne	in_ram1
			lda	#os_ram1
			sta	rw_control
			sta	smos_data
			jsr	control_line
			mea	smosram1,sm_cfg
not_ram:		rts
;
do_ram:
			ldy	#$00
do_ram1:		lda	current_os,y
			cmp	ram_os,y
			bne	cannot
			iny
			cpy	#4
			bne	do_ram1
			lda	#os_ram
			sta	rw_control
			sta	smos_data
			jsr	control_line
			mea	smosram,sm_cfg
do_not_ram: rts
cannot:
			jsr	printsi
			dc.b	$9b," Sorry CRC's Did not MATCH",$9B
			dc.b	" Request aborted!",$9B,-1
			jmp	pause
;
			dc.b	$9b,$9b


;--------------------------
store:			dc.b	$04,$04
store1:			dc.b	$00,$00
store2:			dc.w	memory
rik:			dc.w	ric
line:			dc.w	line1
v_bootup:		dc.w	bootup
v_trap:			dc.w	start
recurse:		dc.b	0
;
in_vbi:			dc.b	0
trap:
			lda	v_bootup
			sta	$02e7
			lda	v_bootup+1
			sta	$02e7+1
			lda	$0224
			sta	exit+1
			lda	$0225
			sta	exit+2
			ldy	#top_init&$ff
			ldx	#top_init/256
			lda	#7
			jsr	setvbv
			lda	#$00
			sta	shflok
			sta	invflg
			rts
;
;
;
top_init:
			save
			lda	brkkey
			cmp	#$00
			bne	at_shi
			lda	#$80
			sta	brkkey
			jsr	bbmenu
at_shi:
			lda	consol
;
;
			cmp	#$05			;Select
			bne	smith
			jmp	rob
smith:
;			LDA	$14
;			CMP	RECURSE
;			BEQ	AT_IT
at_tt:
			lda	#$01
			sta	in_vbi
;
;
;			LDA	$02FC
;			CMP	#$8F    		; raw arrow down
;			BEQ	AT_SS
;			CMP	#$0E    		; raw '-' key
;			BEQ	AT_SS
			lda	consol
			cmp	#$03   			; option key
			bne	at_itt
at_ss:    ;  		lda	#$FF
;   			STA	$02FC
			inc	store2
			lda	store2
			cmp	#$00
			bne	at_itt
			inc	store2+1
at_itt:
;			CMP	#$8E    		; raw arrow up
;			BEQ	AT_ST
;			CMP	#$06    		; raw '+' key
;			BEQ	AT_ST
			lda	consol			; Start key
			cmp	#$06
			bne	at_it
at_st:    
;			lda	#$FF
;			STA	$02FC
			inc	store2+1
at_it:
			lda	rik
			sta	fixt+1
			lda	rik+1
			sta	fixt+2
			lda	#$00
			sta	store
			lda	store2+1
			sta	ken+2
			jsr	error
			lda	store2
			sta	ken+1
			jsr	error
;
			ldy	#$00
			lda	line
			sta	fixt+1
			lda	line+1
			sta	fixt+2
			lda	#$00
			sta	store
loop_1:
			inc	store
ken:			lda	$ffff,y
			jsr	error
			iny
			cpy	#11
			bne	loop_1
;
popper:
			pop_word	i.pr_ptr,mhd
			lda	portb
			jsr	s_hex
			mea	s_hex_st,i.pr_ptr
			ldx	#77
			jsr	writes
;
			lda	rw_control
			jsr	s_hex
			mea	s_hex_st,i.pr_ptr
			ldx	#48
			jsr	writes
;
			lda	current_ram_bank
			jsr	spr_byte
			mea	spr_data,i.pr_ptr
			ldx	#55
			jsr	writes
;
			pop_word	mhd,i.pr_ptr
;
rob:
			lda	#$00
			sta	in_vbi
			restore
exit:			jmp	$ffff
			rts
;
mhd:			dc.w	0
my_sjc:
;			dc.b	<internal>,<+128>,"OS_MENU Written by Stephen J Carden v1.7"
 			dc.b	<internal>,<+128>,"RealDos OS_Menu.COM (c)opyright ILS 2012"
			dc.b	<internal>,<+128>,"$"
ric:			dc.b	<internal>,<+128>,"FFFF"
line1:			dc.b	<internal>,<+128>,"                                   "
;
;
error:			pha
			lsr
			lsr
			lsr
			lsr
			jsr	dd_8913
			pla
			and	#$0f
dd_8913:		cmp	#$0a
			bcs	dd_891b
			ora	#$30
			bne	dd_891d
dd_891b:		adc	#$36
dd_891d:		jsr	fxch
			rts
fxch:
			cmp	#32
			bcc	a_dd64
			cmp	#96
			bcc	s_ub32
			cmp	#128
			bcc	fixt1
			cmp	#160
			bcc	a_dd64
			cmp	#244
			bcc	s_ub32
			jmp	fixt1
a_dd64:
			clc
			adc	#64
			jmp	fixt1
s_ub32:
			sec
			sbc	#32
fixt1:
			ldx	store
			eor	#$80
fixt:			sta	$ffff,x
			inc	store
			rts
my_end_mon:
;
;-------------------------------
; END OF MEMORY RESIDENT PORTION
;-------------------------------
;
;
bootup:
;
			lda	v_bootup			;move $02E7 to the
			sta	$02e7				; end of our code..
			lda	v_bootup+1
			sta	$02e7+1
top:			lda	$0224
			sta	exit+1
			lda	$0225
			sta	exit+2
;   LDA TOP_HAT
;   STA $0224
;   LDA TOP_HAT+1
;   STA $0225
			ldy	#top_init&$ff
			ldx	#top_init/256
			lda	#7
			jsr	setvbv
shit:
			lda	$0c
			sta	trap+1
			lda	$0c+1
			sta	trap+2
			lda	v_trap
			sta	$0c
			lda	v_trap+1
			sta	$0c+1
			lda	#$4c 				; jmp instruction
			sta	shit
			mea	my_mon,shit+1
;
my_mon:
			jsr	printsi
			dc.b	$7d,$9b,$9b,$9b
			dc.b	"     "
			dc.b	<+128>,""
			dc.b	$9B
			dc.b	"     "
			dc.b	<+128>,"|  Super Memory Monitor  |"
			dc.b	$9B
			dc.b	"     "
			dc.b	<+128>,"|       Written by       |"
			dc.b	$9B
			dc.b	"     "
			dc.b	<+128>,"|    Stephen J. Carden   |"
			dc.b	$9B
			dc.b	"     "
			dc.b	<+128>,"|Smartos hardware Design |"
			dc.b	$9B
			dc.b	"     "
			dc.b	<+128>,"|   By Bob Woolley and   |"
			dc.b	$9B
			dc.b	"     "
			dc.b	<+128>,"|    Stephen J. Carden   |"
			dc.b	$9B
			dc.b	"     "
			dc.b	<+128>,"| Press Start or option  |"
			dc.b	$9B
			dc.b	"     "
			dc.b	<+128>,"|   Select to freeze     |"
			dc.b	$9B
			dc.b	"     "
			dc.b	<+128>,""
			dc.b	$9B,$FF
			jsr	pause
			lda	#$7d
			jsr	echo
			rts
;
spr_data:		dc.b	0,"123456"
spr_byte:
			ldx	#$00
spr_card:
			sta	fr0
			stx	fr0+1
			lda	#$00
			sta	cix
			jsr	ifp
			jsr	fasc
			ldy	#$00
s.aprbloop:
			lda	(inbuff),y
			php
			and	#$7f
			iny
			sta	spr_data,y
			sty	spr_data
			plp
			bpl	s.aprbloop
			rts


;
;    Status Line Functions
;    ---------------------
;
;    File: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
;
;
init_status:		lda	#0		;plot initial status lines
			jsr	clr_stat
			lda	#1
			jsr	clr_stat
			lda	#2
			jsr	clr_stat
			lda	#3
			jsr	clr_stat
			lda	#4
			jsr	clr_stat
			lda	#0
			sta	inverse
			jsr	my_wait
			pop_word	os_type,i.pr_ptr
			ldx	#1
			jsr	writes
			pop_word	sm_cfg,i.pr_ptr
			ldx	#18
			jsr	writes
;
			mea	a.cnt_point,i.pr_ptr
			ldx	#41
			jsr	writes
			mea	a.cnt_portb,i.pr_ptr
			ldx	#70
			jsr	writes
			mea	a.cnt_ram,i.pr_ptr
			ldx	#51
			jsr	writes
;
;
			lda	#os_write
			bit	rw_control
			beq	willis
			mea	a.os_mode,i.pr_ptr
			jmp	willis1
willis:			mea	a.os_mode1,i.pr_ptr
willis1:		ldx	#60
			jsr	writes
			mea	memo1,i.pr_ptr
			ldx	#81
			jsr	writes
			mea	memo2,i.pr_ptr
			ldx	#121
			jsr	writes
			rts
;
a.cnt_point:		dc.b	7,"$d380 $"
a.cnt_portb:		dc.b	7,"$d301 $"
a.cnt_ram:		dc.b	4,"Ram "
a.os_mode:		dc.b	5,"Write"
a.os_mode1:		dc.b	5,"     "
current_ram_bank:	dc.b	0
memo1:			dc.b	0
			ds.b	40
memo2:			dc.b	0
			ds.b	40
;
;    updates all of the fields in the status box
;    -------------------------------------------
;
statbox:		lda	in_vbi
			cmp	#$00
			bne	statbox
			ldx	#$00
			txa
.sbcl:			sta	statline,x
			sta	statline+40,x
			sta	statline+80,x
			sta	statline+120,x
			sta	statline+160,x
			inx
			cpx #39     ;  24
			bcc	.sbcl
			jsr	init_status
			jsr	file_stat
			rts
;
;    clear status line in A
;    ----------------------
;
clr_stat:		tay
			lda	.ofst,y
			tay
			lda	#0
			tax
.clear:			sta	statline,y
			iny
			inx
			cpx	#40
			bne	.clear
			rts
.ofst:			dc.b	0,40,80,120,160,200
;
;    plot the name of current open file on status line
;    -------------------------------------------------
;
file_stat:		sty	.tempy
			stx	.tempx
			sta	.tempa
			ldy	#0
			tya
.fclear:		sta	statline+160,y		;clear out what was there
			iny
			cpy	#40
			bne	.fclear
			ldy	#0
.floop:			lda	(i.fn_ptr),y
			beq	.done
			cmp	#$9b
			beq	.done
			jsr	locase  ;to UPPER case
			jsr	xlate
			sta	statline+161,y
			iny
			cpy	#38
			bne	.floop
.done:
;
			ldy	.tempy
			lda	.tempa
			ldx	.tempx
			rts
.tempy:			dc.b	0
.tempx:			dc.b	0
.tempa:			dc.b	0
;
;  writes: writes string with address in i.pr_ptr, length byte in 0th byte
;    Must enter with correct offset already in X!
;  --------------------------------------------------------------------
;
writes:			ldy	#0
			lda	(i.pr_ptr),y ;get length to print
			beq	.xwri   ;exit, null string
			sta	.maxlth
			inc	.maxlth
			iny
.pril:			lda	(i.pr_ptr),y
			jsr	xlate
			sta	statline,x
			inx
			iny
			cpy	.maxlth
			bne	.pril
.xwri:			rts
;
.maxlth:		dc.b	0
;
xlate:			and	#$7f
			cmp	#32
			bcc	.add64
			cmp	#97
			bcs	.nuttin
.sub32:			sec
			sbc	#32
			jmp	.nuttin
.add64:			clc
			adc	#64
.nuttin:		ora	inverse
			rts
.temp:			dc.b	1
;
inverse:		dc.b	0
;
;
s_cardd:		dc.b	$00
;
; print a hex word value
; low byte in a reg x is high byte
;
s_card:			sta	s_cardd
			txa
			ldy	#$01
			jsr	s_hex_conv
			lda	s_cardd
			jsr	s_hex_conv
			rts
;
;
s_hex:
			sty	hold_this_xy+1
			stx	hold_this_xy
			ldy	#$01
			jsr	s_hex_conv
			ldy	hold_this_xy+1
			ldx	hold_this_xy
			rts
;
;
hold_this_xy:		dc.b	0,0
;
s_hex_st:		dc.b	0,0,0,0,0
;
s_hex_conv:		pha
			lsr
			lsr
			lsr
			lsr
			jsr	s_8913
			pla
			and	#$0f
s_8913:			cmp	#$0a
			bcs	s_891b
			ora	#$30
			bne	s_891d
s_891b:			adc	#$36
s_891d:			sta	s_hex_st,y
			iny
			sty	s_hex_st
			lda	#$20
			sta	s_hex_st,y
			rts
;
;
;
data:			dc.b	0     ;    ds.b S 128+1
count:			dc.b	0
r_d301:			dc.b	0
f_mem:			dc.b	0
;
bank_mem:
			lda	total_banks
			cmp	#$00
			bne	m9
			jsr	printsi
			dc.b	$9b,$9b," No Extra Ram found!",$9B,-1
			jmp	pause
;
m9:			lda	total_banks
			sta	f_mem
			inc	f_mem
			lda	#$01
			sta	count
			lda	#$00
			sta	data
;			STA	COUNT
			sta	r_d301
			jsr	printsi
			dc.b	$7d,$9b,"Bank Memory Routeen!",$9B,-1
;
			lda	portb
			sta	r_d301
bank_select:
			lda	count
			sta	current_ram_bank
			jsr	printsi
			dc.b	$9b," Purging Bank ",-1
			sei
			ldy	count
			tya
			jsr	pr_byte
			cli
			ldy	count
			lda	total_banks,y
			eor	xor_byte
			sta	data					; was data,y
			lda	data					; was DATA,Y
			pha
			jsr	printsi
			dc.b	"  $",-1
			pla
			jsr	drive_error
			ldy	count
			lda	total_banks,y
			pha
			jsr	printsi
			dc.b	"  $",-1
			pla
			pha
			jsr	drive_error
			pla
; making sure we don't turn off the os by mistake
			lda	data
			sta	portb
			jsr	bank_purge1
wsrc:			lda	r_d301
			sta	portb
			lda	count
			cmp	f_mem
			bne	bank_select
			lda	#$00
			sta	current_ram_bank
			lda	r_d301
			sta	portb
;
			jsr	pause
			rts
;
bank_purge1:
			inc	count
			lda	$0701
			cmp	#$40
			bcs	bp3
			lda	consol
			cmp	#$07
			beq	bp1
;
bp3:
			lda	portb
			cmp	#$62				; $E3
			beq	bp2
			cmp	#$66				; $E7
			beq	bp2
			cmp	#$6a				; $EB
			beq	bp2
			cmp	#$6e				; $EF
			beq	bp2
bp1:
			jsr	bank_purge
			lda	r_d301
			sta	portb
			rts
;
bp2:
			lda	r_d301
			sta	portb
			jsr	printsi
			dc.b	$9b," Base 64k skipped",$9B,-1
			rts
;
;
;
;       Dos Utititys
;
s_dos:
			ldx	#disk_2
			jsr	close
			jsr	printsi
			dc.b	$7d,$9b,$9b,$9b
			dc.b	" SMART OS Dos Function menu!",$9B,$9B
			dc.b	" "
			dc.b	<+128>,"[1]"
			dc.b	" Directory",$9B
			dc.b	" "
			dc.b	<+128>,"[2]"
			dc.b	" Change Working Directory",$9B
			dc.b	" "
			dc.b	<+128>,"[3]"
			dc.b	" Erase File(s)",$9B
			dc.b	" "
			dc.b	<+128>,"[4]"
			dc.b	" Make Directory",$9B
			dc.b	" "
			dc.b	<+128>,"[5]"
			dc.b	" Delete Directory",$9B
			dc.b	" "
			dc.b	<+128>,"[6]"
			dc.b	"                         ",$9B
			dc.b	" "
			dc.b	<+128>,"[7]"
			dc.b	"                         ",$9B
			dc.b	" "
			dc.b	<+128>,"[8]"
			dc.b	"                         ",$9B
			dc.b	" "
			dc.b	<+128>,"[M]"
			dc.b	"ain menu!",$9B
			dc.b	$9b,$9b," Selection ",-1
			mea	m_dos_table,i.s_ptr
			jsr	my_key
			jsr	execute
			jmp	s_dos
;
m_dos_table:
			dc.b	"1"
			dc.w	dos_dir
			dc.b	"2"
			dc.w	dos_cwd
			dc.b	"3"
			dc.w	dos_erase
			dc.b	"4"
			dc.w	dos_mkdir
			dc.b	"5"
			dc.w	dos_deldir
			dc.b	"M"
			dc.w	main_menu
			dc.b	"X"
			dc.w	t_exit
			dc.b	$1b
			dc.w	t_exit
			dc.b	"*"
			dc.w	s_inspect
			dc.b	"I"
			dc.w	s_inspect
			dc.b	"H"
			dc.w	my_put
			dc.b	"D"
			dc.w	s_put
			dc.b	$7d
			dc.w	reset
			dc.b	"'"
			dc.w	os_on
			dc.b	"!"
			dc.w	os_off
			dc.b	0
			dc.w	s_done
;

t_exit:
;          pop_word  sdlstl,i_sc_hold_dlist
;          pop_word  savmsc,d_l_mem
			jmp	s_exit




more:
			jsr	printsi
			dc.b	<+128>,"[ - MORE - ]"
			dc.b	-1
			jsr	get_key
			cmp	#$7e    ; BACKSPACE
			beq	esc_more
			jsr	printsi
			dc.b	$7e,$7e,$7e,$7e
			dc.b	$7e,$7e,$7e,$7e
			dc.b	$7e,$7e,$7e,$7e
			dc.b	-1
			lda	#0
			sta	count
			rts
;
esc_more:
			ldx	#disk_2
			jsr	close
			pla
			pla
			rts
;
dos_dir:
			jsr	dos_string
			ldx	#disk_2
			jsr	close
			ldx	#disk_2
			jsr	opendir
			lda	#0
			sta	count
;
;
dos_dir_loop:
			mea	in_str,i.in_ptr
			lda	#40
			ldx	#disk_2
			jsr	inputsd
			bmi	dos_dir_done
			mea	in_str,i.pr_ptr
			jsr	echos
			jsr	cr_lf
			inc	count
			lda	count
			cmp	#14
			bcc	dos_dir_loop
			jsr	more
			jmp	dos_dir_loop
;
dos_dir_done:
			ldx	#disk_2
			jsr	close
			jmp	pause
;
;
dos_mkdir:
			jsr	dos_string
			ldx	#disk_2
			jsr	credir
			rts
dos_cwd:		jsr	dos_string
			ldx	#disk_2
			jsr	cwd
			rts
dos_erase:		jsr	dos_string
			ldx	#disk_2
			jsr	erase
			rts
dos_deldir:		jsr	dos_string
			ldx	#disk_2
			jsr	deldir
			rts
;
;
dos_string:
			jsr	printsi
			dc.b	$9b,$9b," Enter String"
			dc.b	$9b," :",-1
			jsr	get_str
			dc.w	parm_1
			dc.b	68,0,1
			mea	parm_1,i.s_ptr
			jsr	upstring
			mea	parm_1,i.s_ptr
			mea	parm_2,i.d_ptr
			jsr	toascii
			mea	parm_2,i.fn_ptr
			jsr	file_stat
			ldx	#disk_2
			jsr	close
			mea	parm_2,i.fn_ptr
			jsr	printsi
			dc.b	$9b,$9b,-1
			rts
;

A_end:
;
;
;
;  I am not sure if I wan to keep this or not
;
;
;
;
;
         .org  $8000

;
;-----------------------------
;This part of the program
;will read the cart out and
;turn it into a binary file!
;
;
read_cart:
			ldx	#disk_2
			jsr	close
;
			ldx	#disk_2
			lda	#3
			sta	iccom,x
			lda	# low os_name
			sta	icbal,x
			lda	# high os_name
			sta	icbah,x
			lda	#8
			sta	icax1,x
			lda	#0
			sta	icax2,x
			jsr	ciov
;
			ldx	#disk_2
			lda	#$0b
			sta	iccom,x
			lda	# low l40ec			; $EC
			sta	icbal,x
			lda	# high l40ec			; $40
			sta	icbah,x
			lda	# high 1			; 0
			sta	icblh,x
			lda	# low 1				; 1
			sta	icbll,x
;
l4043:			jsr	ciov
			inc	icbal,x
			lda	icbal,x
			cmp	#0
			bne	l4053
			inc	icbah,x
l4053:			lda	icbal,x
			cmp	# low cart_end-1		; $B3
			bne	l4043
			lda	icbah,x
			cmp	# high cart_end-1		; $41
			bne	l4043
			jsr	ciov
;
			ldx	#disk_2
			lda	#$0b
			sta	iccom,x
			lda	# low cart_a			;$00
			sta	icbal,x
			lda	# high cart_a			;$A0
			sta	icbah,x
			lda	# high 1			; 0
			sta	icblh,x
			lda	# low 1				; 1
			sta	icbll,x
;
l407f:			jsr	ciov
			inc	icbal,x
			lda	icbal,x
			cmp	#0
			bne	l408f
			inc	icbah,x
l408f:			lda	icbal,x
			cmp	# low cart_a+cart_l		; $FF
			bne	l407f
			lda	icbah,x
			cmp	# high cart_a+cart_l		; $BF
			bne	l407f
			jsr	ciov
			lda	# low l40e6 ;$E6
			sta	icbal,x
			lda	# high l40e6 ;$40
			sta	icbah,x
			jsr	ciov
;
			inc	icbal,x
			jsr	ciov
;
			inc	icbal,x
			jsr	ciov
;
			inc	icbal,x
			jsr	ciov
;
			inc	icbal,x
			jsr	ciov
;
			inc	icbal,x
			jsr	ciov
;
;close disk 1
			ldx	#disk_2
			jsr	close
			rts
;
;
;
l40e6:			dc.w	$02e0
			dc.w	$02e1
			dc.w	l0600 ; $0600
;
;
;This is Normal Header stuff
;for a binary file
;
;
;
l40ec:			dc.w	$ffff
			dc.w	l0600 ;   $0600
			dc.w	end_page_6-1 ;   $0647
end_of_copy:
;
;
;
;	I really need to remove this code
;
;
;
;
;
;
;----------------------------
; This get added to the cart
;program to allow it to run
;out of the rom.
;
;
;----------------------------
page_6:
;        .SET 6,[PAGE_6-L0600]
;
;
;
         .org  $0600
l0600:
			lda	dosini
			sta	l9b64+1
			lda	dosini+1
			sta	l9b64+2
			lda	# low l9b60			;  $60
			sta	dosini
			lda	# high l9b60			;  $9B
			sta	dosini+1
			lda	# low $bc00			;  $00
			sta	i.d_ptr
			lda	# low $9b00			;  $00
			sta	i.s_ptr
			lda	# high $bc00			; $BC
			sta	i.d_ptr+1
			lda	# high $9c00			; $9C
			sta	i.s_ptr+1
;
;-----------------------------
; copying screen memory
; so the cart can run
;
;
;
			ldy	#0
l0624:			lda	(i.d_ptr),y
			sta	(i.s_ptr),y
			iny
			cpy	#0
			bne	l0624
			inc	i.d_ptr+1
			lda	i.d_ptr+1
			cmp	#$c0
			beq	l063c
			inc	i.s_ptr+1
			ldy	#0
			jmp	l0624
;
l063c:			lda	#1
			sta	boot.
			lda	#0
			sta	coldst
			jmp	cart_a
end_page_6:
;
;----------------------------
;reseting the offset compile
;
;
;----------------------------
;
;        .SET 6,[END_PAGE_6-END_PAGE_6]
         .org  page_6+end_page_6-l0600
;
;
l413a:			dc.w	l9b60		; $9B60
l413c:			dc.w	l9bcb		; $9BCB
;
;
junk:
;
;----------------------------
;Once again doing an offset
;compile!
;
;This also get's saved with
;the cart program
;----------------------------
;        .SET 6,-[L9B60-JUNK]
;
;
         .org  $9b60
;
l9b60:
			lda	#$ff
			sta	warmst
l9b64:			jsr	$00
			jsr	l9ba1
			lda	# low $9c00 ;$00
			sta	i.d_ptr
			lda	# low $bc00 ;$00
			sta	i.s_ptr
			lda	# high $9c00 ;$9C
			sta	i.d_ptr+1
			lda	# high $bc00 ;$BC
			sta	i.s_ptr+1
			ldy	#0
l9b7c:			lda	(i.d_ptr),y
			sta	(i.s_ptr),y
			iny
			cpy	#0
			bne	l9b7c
			inc	i.d_ptr+1
			lda	i.d_ptr+1
			cmp	#$a0
			beq	l9b94
			inc	i.s_ptr+1
			ldy	#0
			jmp	l9b7c
;
l9b94:			lda	# low l9b60 
			sta	dosini
			lda	# high l9b60 
			sta	dosini+1
			jmp	cart_a
;
l9b9f:
			dc.b	"S:"
;
l9ba1:
			lda	#$98
			sta	ramtop
			ldx	#disk_3
			lda	#3
			sta	iccom,x
			lda	# low l9b9f 
			sta	icbal,x
			lda	# high l9b9f 
			sta	icbah,x
			lda	#8
			sta	icax1,x
			lda	#0
			sta	icax2,x
			jsr	ciov
			lda	#$0c
			sta	iccom,x
			jsr	ciov
l9bcb:			rts
end_of_9b:
;
;        .SET 6,[END_OF_9B-END_OF_9B]
         .org  junk+end_of_9b-l9b60
;
;
l41aa:
			dc.w	$02e2
			dc.w	$02e3
			dc.w	l9ba1				; $9BA1
			dc.w	cart_a
			dc.w	cart_a+cart_l			; $BFFF
;
cart_end:
;
;


;
;------------------------------
word:			ds.b	30
i.bufoff:		dc.b	0
;
upcase:			cmp	#'a'
			bcc	xupcase
			cmp	#'z'+1
			beq	xupcase
			bcs	xupcase
			sec
			sbc	#32
xupcase:		rts
;
locase:			cmp	#'A'
			bcc	xlocase
			cmp	#'Z'+1
			beq	xlocase
			bcs	xlocase
			clc
			adc	#32
xlocase:		rts
;
;
;    Move string pointed to by i.s_ptr to string pointed to by i.d_ptr
;    -------------------------------------------------------------
;
move_str:		ldy	#0
			lda	(i.s_ptr),y		;get lth byte
			tay				;go backwards
.dloop:			lda	(i.s_ptr),y
			sta	(i.d_ptr),y
			cpy	#0
			beq	A.done
			dey
			jmp	.dloop
A.done:			rts
;
;    Return the length of string at i.s_ptr in accumulator
;  -------------------------
length:			ldy	#0
			lda	(i.s_ptr),y
			rts
;
;    Concatenate the string at i.s_ptr onto the end of string at i.d_ptr
;    ---------------------------------------------------------------
;
concat:			ldy	#0
			lda	(i.s_ptr),y		;get source lth
			sta	.srclth
			beq	.bend			;null string..exit
			lda	(i.d_ptr),y		;get dest lth
			sta	.desty
			inc	.srcy
			inc	.desty
			ldy	#1			;always start at 1 on
			sty	.srcy			; the source string
.cloop:			ldy	.srcy
			lda	(i.s_ptr),y		;get byte from source
			ldy	.desty
			sta	(i.d_ptr),y		;store into dest
			lda	.srcy
			cmp	.srclth			;end of string?
			beq	.bend			;yes
			inc	.srcy
			inc	.desty			;up indexes
			bne	.cloop			;and keep going
.bend:			ldy	#0
			lda	(i.d_ptr),y		;up the length byte
			clc				; of the dest string
			adc	.srclth
			sta	(i.d_ptr),y
			rts
;
.srcy:			dc.b	1
.desty:			dc.b	1
.srclth:		dc.b	1
;
;    input a string from device in X register
;    into the string pointed to by i.in_ptr.
;    ----------------------------------------
;
inputsd:		sta	icbll,x			;length is in the accum already
			lda	#ccgetrec
			sta	iccom,x
			lda	i.in_ptr
			clc
			adc	#1			;offset past length byte
			sta	icbal,x
			lda	i.in_ptr+1
			adc	#0
			sta	icbah,x
			lda	#0
			sta	icblh,x			;zero hi byte of length
			jsr	ciov			;get the line
			bmi	.error
.noerror:		lda	icbll,x			;get lth actually read in
			sec
			sbc	#1			; minus 1
			ldy	#0
			sta	(i.in_ptr),y ; and place it in length byte
			rts
;
.error:			sty	.holdy
			ldy	#0
			tya
			sta	(i.in_ptr),y
			ldy	.holdy
			rts
;
.holdy:			dc.b	0
;
;
;  Make an ASCII ($9b terminated) string out of a lth-byte string
;  --------------------------------------------------------------
;
toascii:		ldy	#0
			lda	(i.s_ptr),y		;get lth byte
			sta	.blth
			beq	.null
			iny
			inc	.blth
.bloop:			lda	(i.s_ptr),y
			dey
			sta	(i.d_ptr),y
			iny
			iny
			cpy	.blth
			bne	.bloop
.adone:			ldy	.blth
			dey
.rtn:			lda	#$9b
			sta	(i.d_ptr),y
			rts
.null:			ldy	#0
			beq	.rtn
.blth:			dc.b	1
;
;  Make a length-byte string from an ASCII ($9b terminated) string
;  ---------------------------------------------------------------
;
tostr:			ldy	#0
.tfe:			lda	(i.s_ptr),y		;find end of string
			beq	.gotend
			cmp	#$9b
			beq	.gotend
			iny
			bne	.tfe
.gotend:		sty	.clth			;save length
			cpy	#0
			beq	.artn
			ldy	#0
.aloop:			lda	(i.s_ptr),y
			iny
			sta	(i.d_ptr),y
			cpy	.clth
			bcc	.aloop
.artn:			ldy	#0
			lda	.clth
			sta	(i.d_ptr),y
			rts
;
.clth:			dc.b	1
;
;    ----------------------------------------------
;	turn a length byte ascii number into a card
;    ----------------------------------------------
;
valc:			jsr	length			;get length
			tay
			iny
			lda	#$9b			;install eol
			sta	(i.s_ptr),y
			lda	i.s_ptr
			sta	inbuff
			lda	i.s_ptr+1
			sta	inbuff+1
			lda	#1
			sta	cix
			jsr	afp			;ascii --> floating pt.
			bcs	.default
			jsr	fpi			;floating --> integer
			bcs	.default
			lda	fr0
			ldx	fr0+1
			rts
.default:		lda	#0
			tax
			rts
;
;    Search the string pointed to by i.s_ptr for the substring
;    pointed to by i.d_ptr.  Returns a 0 if substring not found.
;    ---------------------------------------------------------
;
substr:			ldy	#0
			lda	(i.s_ptr),y
			sta	.s_lth
			lda	(i.d_ptr),y
			sta	.d_lth
			lda	i.s_ptr
			sta	.comp+1
			lda	i.s_ptr+1
			sta	.comp+2
			lda	i.d_ptr
			sta	.get+1
			lda	i.d_ptr+1
			sta	.get+2
			lda	#1
			sta	.loc
			ldy	#0
			ldx	#0
			jsr	.up_str
			jsr	.up_sub
;
.comp:			lda	$ffff,y
			jsr	upcase
			sta	.atemp
.get:			lda	$ffff,x
			jsr	upcase
			cmp	.atemp
			beq	.match
.nomatch:		ldx	#1
			inc	.loc
			jsr	.up_str
			jmp	.comp
.match:			jsr	.up_sub
			jsr	.up_str
			jmp	.comp
;
.up_str:		iny
			cpy	.s_lth
			bcc	.xup
			beq	.xup
			pla
			pla
			lda	#0
;
.xup:			rts
;
.up_sub:		inx
			cpx	.d_lth
			bcc	.xsub
			beq	.xsub
			pla
			pla
			lda	.loc
;
.xsub:			rts
;
.atemp:			dc.b	0
.loc:			dc.b	0
.s_lth:			dc.b	0
.d_lth:			dc.b	0
;
;  prints: prints string with address in i.pr_ptr, length byte in 0th byte
;  --------------------------------------------------------------------
prints:
echos:
pri2:
			ldy	#0
			lda	(i.pr_ptr),y			;get length to print
			beq	a.xpri				;exit, null string
			sta	a.amaxlth
			iny
			sty	tempy
a.pril:			ldy	tempy
			lda	(i.pr_ptr),y
			jsr	fast_output
a.prnext:		inc	tempy
			dec	a.amaxlth
			bne	a.pril
a.xpri:			rts
tempy:			dc.b	1
a.amaxlth:		dc.b	1
;
;--------------------
;
open_kbd:		ldx	#kbd
			lda	#ccclose
			sta	iccom,x
			jsr	ciov				;do the close
			bmi	open_kbd			;remain until it works OK.
			ldx	#kbd
			lda	#ccopen
			sta	iccom,x
			jsr	load_k
			sta	icax2,x
			lda	#4				;input mode
			sta	icax1,x
			jsr	ciov
			bmi	open_kbd			;keep trying till it works!
			rts
;

; ---------------------------
;    get_str gets an input line into the specified string.
;
;    input:  address of string in i.in_ptr
;      A - max length
;      X - mask (0=alpha/numeric, 1=numeric)
;      Y - allow return key only (1=yes)
;
;  length of inputted string is returned in the 0th position (and A)
; -------------------------------------------------------------------
get_str:		pla         			;entry here, parms on stack
			sta	i.pr_ptr
			pla
			sta	i.pr_ptr+1
			ldy	#1
			lda	(i.pr_ptr),y 		;get address lo
			sta	i.in_ptr
			iny
			lda	(i.pr_ptr),y 		;   address hi
			sta	i.in_ptr+1
			iny
			lda	(i.pr_ptr),y 		;   length byte
			sta	b.gsa
			iny
			lda	(i.pr_ptr),y 		;   mask
			sta	b.gsx
			iny
			lda	(i.pr_ptr),y 		;   return allowed?
			sta	b.gsy
			lda	i.pr_ptr  		;now, correct stack
			clc
			adc	#5
			sta	i.pr_ptr
			lda	i.pr_ptr+1
			adc	#0
			pha
			lda	i.pr_ptr
			pha
			lda	b.gsa
			ldx	b.gsx
			ldy	b.gsy
			jmp	get_string
b.gsa:			dc.b	0
b.gsx:			dc.b	0
b.gsy:			dc.b	0
get_string:		cmp	#83			;max < 83?
			bcc	b.gsentry 		;yes
			lda	#80
b.gsentry:		sta	b.maxlth 		;save max length
			stx	b.mask
			sty	b.return
			lda	i.in_ptr
			sta	b.address 		;hold address of string
			lda	i.in_ptr+1 		; to input into
			sta	b.address+1
			lda	#0
			sta	b.instr  		;zero length byte
b.gsloop:		jsr	get_key 		;get a keypress
			CMP	#'\'			;can't allow this key!
			BEQ	b.GSLOOP		;yes, ignore
			cmp	#$9b    		;carriage return?
			bne	b.nogs   		;nope
			jmp	b.gscr   		;yes
b.nogs:			cmp	#14     		;treat ^N as a C/R
			bne	b.not14
			jmp	b.gscr
b.not14:		cmp	#126    		;backspace?
			beq	b.bspace
			cmp	#30
			beq	b.bspace
			cmp	#24     		;^X?
			bne	b.nowipe
			jmp	b.wipeout
b.nowipe:		and	#$7f    		;strip inverse bit
			sta	b.akey   		;hold it
;    now, see if it falls within requested mask
;    ------------------------------------------
			ldx	b.mask   		;get mask
			beq	b.alphanum
			cpx	#1
			beq	b.numeric
b.alphanum:		cmp	#32    			; < space?
			bcc	b.gsloop 		;yes, ignore
			cmp	#'z'+1   		; > 'z'
			bcs	b.gsloop 		;yes, ignore
			jmp	b.gsstore
b.numeric:		cmp	#'0'          		; < '0'?
			bcc	b.gsloop 		;yes, ignore
			cmp	#'9'+1   		; > '9'
			bcs	b.gsloop 		;yes, ignore
			jmp	b.gsstore
b.gsstore:		lda	b.instr  		;get length byte
			cmp	b.maxlth
			beq	b.gsloop 		;ignore it..at
			bcs	b.gsloop 		; max length now
			tay
			iny
			lda	b.akey
			cmp	#32     		;is it a space?
			bne	b.notspc 		;nope
			cpy	#1      		;1st char in line?
			bne	b.notspc
			jmp	b.gsloop 		;yes..don't allow it
b.notspc:		sta	b.instr,y		;save key into string
			inc	b.instr			;increase length
b.nohide:		lda	b.akey
b.showit:		jsr	echo
			lda	b.maxlth		;one-key input?
			cmp	#1
			bne	b.nohot			;nope
			lda	b.instr
			cmp	#1			;1 byte entered?
			bne	b.nohot
b.nohot:		jmp	b.gsloop		;keep cookin..
b.bspace:		lda	b.instr			;can't backspace
			cmp	#0			; if no length!
			bne	b.nt0
			jmp	b.gsloop
b.nt0:			dec	b.instr			;-1 to length byte
			lda	#126			;output a BSpace
			jsr	echo
			jmp	b.gsloop
b.wipeout:		lda	b.instr			;can't backspace if no length
			bne	b.wt0
			jmp	b.gsloop
b.wt0:			dec	b.instr  		;-1 to length byte
			lda	#126    		;output a BSpace
			jsr	echo
			jmp	b.wipeout 		;go until line cleared
b.gscr:			lda	b.instr  		;get length
			bne	b.nonull 		;its not null
			ldx	b.return 		;allow return only?
			bne	b.nonull 		;yes..exit
			jmp	b.gsloop 		;nope..ignore it
;    done, so move our string into where they want it.
;    -------------------------------------------------
b.nonull:		lda	i.s_ptr
			sta	b.aholds
			lda	i.s_ptr+1
			sta	b.aholds+1
			lda	i.d_ptr
			sta	b.holdd
			lda	i.d_ptr+1
			sta	b.holdd+1
			mea	b.instr,i.s_ptr
			lda	b.address
			sta	i.d_ptr
			lda	b.address+1
			sta	i.d_ptr+1
			jsr	move_str ;move to their area..
			lda	b.aholds
			sta	i.s_ptr
			lda	b.aholds+1
			sta	i.s_ptr+1
			lda	b.holdd
			sta	i.d_ptr
			lda	b.holdd+1
			sta	i.d_ptr+1
;   LDA #0
;   STA HIDE
			lda	b.instr  ;return with lth in A
			rts
b.address:		dc.b	0,0
b.aholds:		dc.b	0,0
b.holdd:		dc.b	0,0
b.maxlth:		dc.b	0
b.mask:			dc.b	0
b.return:		dc.b	0
b.akey:			dc.b	0
b.instr:		ds.b	86
;    gets a BYTE value - returned in Accum

;    -------------------------------------
get_byte:		jsr	get_str
			dc.w	.work
			dc.b	3,1,0
			tay
			iny
			lda	#$9b    ;install eol
			sta	.work,y
			mea	.work,inbuff
			lda	#1
			sta	cix
			jsr	afp     ;ascii --> floating pt.
			bcs	.adefault
			jsr	fpi     ;floating --> integer
			bcs	.adefault
			lda	fr0+1   ;enter > 255?
			bne	.ovfl   ;yes
			lda	fr0
			rts
.ovfl:			lda	#255
			rts
.adefault:		lda	#0
			rts
.work:			ds.b	6
;    gets a CARD value - returned in A/X
;    -----------------------------------
get_card:		jsr	get_str
			dc.w	.awork
			dc.b	5,1,0
			tay
			iny
			lda	#$9b    ;install eol
			sta	.awork,y
			mea	.awork,inbuff
			lda	#1
			sta	cix
			jsr	afp     ;ascii --> floating pt.
			bcs	.default
			jsr	fpi     ;floating --> integer
			bcs	.default
			lda	fr0
			ldx	fr0+1
			rts
.default:		lda	#0
			tax
			rts
.awork:			ds.b	10


execute:
			jsr	upcase
			sta	.key
			ldy	#0
..loop:			lda	(i.s_ptr),y
			beq	.found
			cmp	.key
			beq	.found
			iny
			iny
			iny
			bne	..loop
.found:			iny
			lda	(i.s_ptr),y
			sta	.goaddr+1
			iny
			lda	(i.s_ptr),y
			sta	.goaddr+2
.goaddr:		jmp	$ffff
.key:			dc.b	0
;
;
;
load_k:			lda	#kdev&$ff
			sta	icbal,x
			lda	#kdev/256
			sta	icbah,x
			lda	#4
			sta	icbll,x
			lda	#0
			sta	icblh,x
			rts
;
;
kdev:			dc.b	"K:",$9B,0
;
sss_e:			dc.b	0
sss:			dc.b	"D380"
			dc.b	0,0,0
sss_data:		dc.w	0
;
steve_pack:
			lda	#$00
			sta	sss_data
			sta	sss_data+1
;
			lda	sss
			jsr	upcase
			sta	sss
;
			lda	sss+1
			jsr	upcase
			sta	sss+1
;
			lda	sss+2
			jsr	upcase
			sta	sss+2
;
			lda	sss+3
			jsr	upcase
			sta	sss+3
;
			ldy	#$00
			ldx	#$00
			jsr	start_crunch
			ldy	#$01
			jsr	start_crunch
			ldy	#$02
			ldx	#$01
			jsr	start_crunch
			ldy	#$03
			jsr	start_crunch
			ldy	sss_data+1
			ldx	sss_data
         stx sss_data+1
			sty	sss_data
			rts
;
start_crunch:
			lda	sss,y
			cmp	#'0'
			bne	jole
			lda	#$00
			beq	jole1
jole:			cmp	#'0'-1
			bcc	hex_it__error
			cmp	#'9'+1
			bcs	hex_it_
			lda	sss,y
         		sbc	#47
jole1:			sta	sss,y
			jmp	hex_it_1
hex_it_:
			cmp	#'A'-1
			bcc	hex_it__error
			cmp	#'F'+1
			bcs	hex_it__error
			lda	sss,y
         		sbc	#54     ;  $36
			sta	sss,y
hex_it_1:
			cpy	#$02
			beq	hex_it_2
			cpy	#$00
			beq	hex_it_2
			lda	sss,y
			eor	sss_data,x
			sta	sss_data,x
			rts
hex_it_2:
			lda	sss,y
			asl
			asl
			asl
			asl
			eor	sss_data,x
			sta	sss_data,x
			rts
;
hex_it__error:		lda	#$ff
			sta	sss_e
			rts
;
upstring:		ldy	#0
			lda	(i.s_ptr),y			;get lth byte
			tay					;go backwards
._dloop:		lda	(i.s_ptr),y
			jsr	upcase
			sta	(i.s_ptr),y
			cpy	#1
			beq	A_.done
			dey
			jmp	._dloop
A_.done:		rts
;
lostring:		ldy	#0
			lda	(i.s_ptr),y			;get lth byte
			tay					;go backwards
..dloop:		lda	(i.s_ptr),y
			jsr	locase
			sta	(i.s_ptr),y
			cpy	#1
			beq	A..done
			dey
			jmp	..dloop
A..done:		rts
;
zzz_e:			dc.b	0
zzz:			dc.b	"-------------------"
zzz_data:		dc.w	0,0,0,0,0
zzz_y:			dc.b	0
zzz_x:			dc.b	0
;
steve_byte:
			ldy	#$00
			lda	#$00
zzz_a:			sta	zzz_data,y
			iny
			cpy	#8+1
			bne	zzz_a
;
			lda	#'-'
			ldy	#$00
zzz_k:			sta	zzz,y
			iny
			cpy	#16+1
			bne	zzz_k
;
			mea	parm_1,i.s_ptr
			jsr	upstring
			mea	parm_1,i.s_ptr
			mea	zzz,i.d_ptr
			jsr	toascii
;
			ldy	#$00
			ldx	#$00
zzz_step:
			jsr	starcrunch
			iny
			jsr	starcrunch
			iny
			inx
			sty	zzz_y
			stx	zzz_x
			cpy	#16+1
			bne	zzz_step
			rts
;
starcrunch:
			lda	zzz,y
			cmp	#'0'
			bne	pole
			lda	#$00
			beq	pole1
pole:			cmp	#'0'-1
			bcc	bit_it__error
			cmp	#'9'+1
			bcs	bit_it_
			lda	zzz,y
			sbc	#47
pole1:			sta	zzz,y
			jmp	bit_it_1
bit_it_:
			cmp	#'A'-1
			bcc	bit_it__error
			cmp	#'F'+1
			bcs	bit_it__error
			lda	zzz,y
			sbc	#54				;  $36
			sta	zzz,y
bit_it_1:
			cpy	#16
			beq	bit_it_2
			cpy	#14
			beq	bit_it_2
			cpy	#12
			beq	bit_it_2
			cpy	#10
			beq	bit_it_2
			cpy	#8
			beq	bit_it_2
			cpy	#6
			beq	bit_it_2
			cpy	#4
			beq	bit_it_2
			cpy	#2
			beq	bit_it_2
			cpy	#0
			beq	bit_it_2
			lda	zzz,y
			eor	zzz_data,x
			sta	zzz_data,x
			rts
bit_it_2:
			lda	zzz,y
			asl
			asl
			asl
			asl
			eor	zzz_data,x
			sta	zzz_data,x
			rts
;
bit_it__error:
			sty	zzz_y
			stx	zzz_x
			lda	#$ff
			sta	zzz_e
			pla
			pla
			rts
;

;
;
os_name:		dc.b	"D1:>TEST_OS.COM",$9B
			ds.b	80
;
xl_os:			dc.b	16,"Atari Stock OSXL"
i.turboss:		dc.b	16,"Turboss OS      "
mux_os:			dc.b	16,"Mux os          "
usp_os:			dc.b	16,"Ultra-Speed + OS"
omnimon:		dc.b	16,"Omnimon XL OS   "
i.turboss_p:		dc.b	16,"Turboss Plus OS "
omniview:		dc.b	16,"Omniview XL     "
unknow_os:		dc.b	16,"Unknow OS       "
os_type:		dc.w	unknow_os
;
;
smosrom:		dc.b	17,"Smartos ROM Mode "
smosram:		dc.b	17,"Smartos RAM Mode "
smosram1:		dc.b	17,"Smartos RAM1 Mode"
smosnot:		dc.b	17,"Standard Config! "
;
sm_cfg:			dc.w	0
;
;
;
;
close:
			lda	#$0c
			sta	iccom,x
			jmp	ciov
;
;------------------------------
; Screen Stuff
;
i_sc_hold_mem:		dc.w	0
i_sc_hold_dlist:	dc.w	0
;
;
init_screen:
			pop_word	savmsc,i_sc_hold_mem
			pop_word	sdlstl,i_sc_hold_dlist
			pop_word	savmsc,d_l_mem
			mea	d_list,sdlstl
			mea	os_name,i.fn_ptr
			jsr	init_status
			jsr	bootup
			rts
;
exit_screen:
			pop_word	i_sc_hold_mem,savmsc
			pop_word	i_sc_hold_dlist,sdlstl
			lda	trap+1
			sta	$0c
			lda	trap+2
			sta	$0c+1
			rts
;
;----------------------------
;
;Moves Rom into Memory
;
rom_to_ram:
			lda	portb
			sta	ghu_hold
;
			mea	memory,i.s_ptr
			mea	os,i.d_ptr
;
;JUST TRYING THIS
			ldy	current_ram_bank
			lda	#$fd
			eor	total_banks,y
			tax
;			LDX	#$FD
			ldy	#$00
;
Alp1:			jsr	Amove_page
			beq	mv_done
			cmp	# high os+$1000 ; $D0
			bne	Alp1
;
			lda	# high memory+$1000 ;$50
			sta	i.d_ptr+1
;
Alp2:			jsr	Amove_page
			cmp	# high memory+$1800 ;$58
			bne	Alp2
;
			lda	# high os+$1800 ;$D8
			sta	i.d_ptr+1
			bne	Alp1
;
Amove_page:		lda	#$7d
			sta	portb
			lda	(i.d_ptr),y
;			LDX	GHU_HOLD		; ADDED CODE
			stx	portb
;			LDX	#$7D			; ADDED CODE
			sta	(i.s_ptr),y
			iny
			bne	Amove_page
;
			inc	i.s_ptr+1
			inc	i.d_ptr+1
			lda	i.d_ptr+1
			rts
ghu_hold: dc.b 0
;
mv_done:  rts
;
;
;----------------------------
;Binary Header stuff
;
os_seg:
			dc.w	memory
			dc.w	memory+os_l
run_os:
			dc.w	$02e2 ; $2E0
			dc.w	$02e3 ; $2E1
			dc.w	ram_to_rom_start
;
;
load_os:
			dc.w	$ffff
			dc.w	ram_to_rom_start
			dc.w	ram_to_rom_end-1
;
;-------------------------
;
;Moves Memory into Rom
;
ram_to_rom_start:
			lda	#$7d
			jsr	echo
			jsr	cr_lf
			jsr	cr_lf
			jsr	cr_lf
			jsr	cr_lf
			jsr	cr_lf
			jsr	cr_lf
			jsr	cr_lf
			mea	rw_screen,i.s_ptr
			ldy	#$00
Aa_rom:			lda	(i.s_ptr),y
			sta	(savmsc),y
			iny
			cpy	#rw_screen_end-rw_screen
			bne	Aa_rom
A_b_rom:		lda	consol
			cmp	#$07    ; no key
			beq	A_b_rom
			cmp	#$06    ; Start key
			beq	ram_to_rom
			rts
;
;
ram_to_rom:
			lda	portb
			sta	rw_hold_d301
			php
			sei
			lda	nmien
			pha
			lda	#$00
			sta	nmien
;
ramon:			lda	rw_control ;$A0
			eor	#os_write
			sta	rw_control
			jsr	control_line
;
			mea	memory,i.s_ptr
			mea	os,i.d_ptr
;
;  Just trying this
;
			lda	rw_mode
			cmp	#$01
			beq	ll_lp1
			ldy	current_ram_bank
			lda	#$7d
			eor	total_banks,y
			tax
;
			dc.b	$2c
ll_lp1:			ldx	#$7d
			ldy	#$00
;
lp1:			jsr	movepage
			beq	complete
			cmp	# high os+$1000 ;$D0
			bne	lp1
			lda	# high memory+$1000 ;$50
			sta	i.d_ptr+1
;
lp2:			jsr	movepage
			cmp	# high memory+$1800 ;$58
			bne	lp2
;
			lda	# high os+$1800 ;$D8
			sta	i.d_ptr+1
			bne	lp1
;
movepage:		lda	#$fd
			sta	portb
			lda	(i.s_ptr),y
;  			ldx	RW_HOLD_D301 ; added code
			stx	portb
;  			ldx	#$fd    ; added code
			sta	(i.d_ptr),y
			iny
			bne	movepage
;
			inc	i.s_ptr+1
			inc	i.d_ptr+1
			lda	i.d_ptr+1
			rts
;
complete:		pla
			sta	nmien
			plp
			lda	#$fd
			lda	ghu_hold
			sta	portb
;
rwoff:			lda	rw_control		;was $C0
			eor	#os_write
			sta	rw_control
			jsr	control_line
			lda	rw_control
			cmp	#os_ram1
			beq	rw_bye
			lda	#$ff
			sta	$0244
			jmp	reset
rw_bye:			rts
rw_hold_d301:		dc.b	0
rw_control:		dc.b	0			;   OS_RAM
rw_control_1:		dc.b	0
rw_line:		dc.w	control
rw_mode:		dc.b	0
;
control_line:
			sta	rw_control_1
			tay
			pop_word	rw_line,i.s_ptr
			tya
			ldy	#$00
			sta	(i.s_ptr),y
			rts
;
printsi:		pla
			sta	pstr+1
			pla
			sta	pstr+2
prsl:			inc	pstr+1
			bne	pstr
			inc	pstr+2
pstr:			lda	$ffff
			cmp	#$ff
			beq	estri
			jsr	fast_output
			jmp	prsl
estri:			lda	pstr+2
			pha
			lda	pstr+1
			pha
			rts
;
;-------------------------
;actual screen handler    
;screen offset definitions
;-------------------------
scr_offset:		dc.w	0
			dc.w	40
			dc.w	80
			dc.w	120
			dc.w	160
			dc.w	200
			dc.w	240
			dc.w	280
			dc.w	320
			dc.w	360
			dc.w	400
			dc.w	440
			dc.w	480
			dc.w	520
			dc.w	560
			dc.w	600
			dc.w	640
			dc.w	680
			dc.w	720
			dc.w	760
			dc.w	800
			dc.w	840
			dc.w	880
			dc.w	920
;
;
;
fast_output:
			sta	$5a
			lda	sc.redirect
			cmp	#print_p
			beq	.go_cio
.leo:
			lda 	$02ff   	; CONTROL 1 FLAG
			cmp 	#$00
			bne 	.leo

			lda	$5a
			cmp	#32
			bcc	.do_look
			cmp	#125
			bcc	.do_here
.do_look:		ldy	#0
.lookup:		lda	.char_table,y
			beq	.do_here
			cmp	$5a
			beq	.go_cio
			iny
			bne	.lookup


.go_cio:		lda	$5a
			jmp	putlocal


.do_here:		ldy	#0
			lda	$5d
			sta	($5e),y
			lda	$5a
			cmp	#$9b
			beq	.docr
.notcr:			jsr	.get_adr
			lda	$5a
			and	#$7f
			cmp	#32
			bcc	.add64
			cmp	#96
			bcc	.sub32
			jmp	.asis
.add64:			clc
			adc	#64
			jmp	.asis
.sub32:			sec
			sbc	#32
.asis:			bit	$5a
			bpl	.xxlate
			ora	#$80
.xxlate:		ldy	#0
			sta	($5e),y
			inc	$55
			inc	$63
			lda	$55
			cmp	#40
			bcs	.next_row
			iny
			lda	($5e),y
			sta	$5d
			ora	#$80
			ldx	752
			bne	.nocurs1
			sta	($5e),y
.nocurs1:		inc	$5e
			bne	.nooav
			inc	$5e+1
.nooav:			rts
.docr:			lda	#0
			sta	$63
.next_row:		lda	$52
			sta	$55
			inc	$54
			ldy	$54
;--------------------------
; can change this next value to reflect to total rows.
			cpy	#24-7
			bcs	.scroll
			jsr	.get_adr
			ldy	#0
			lda	($5e),y
			sta	$5d
			ldx	752
			bne	.nocurs2
			ora	#$80
			sta	($5e),y
.nocurs2:		rts

.scroll:		dec	$54
			lda	$58
			sta	$68
			clc
			adc	#40
			sta	$5e
			lda	$58+1
			sta	$68+1
			adc	#0
			sta	$5e+1
			ldy	#0
			ldx	#3
.scloop:		lda	($5e),y
			sta	($68),y
			iny
			bne	.scloop
			inc	$5e+1
			inc	$68+1
			dex
			bne	.scloop
.scloop2:		lda	($5e),y
			sta	($68),y
			iny
			cpy	#152
			bcc	.scloop2
			lda	$58
			clc
			adc	#920&$ff
			sta	$5e
			lda	$58+1
			adc	#920/256
			sta	$5e+1
			ldy	#0
			tya
.clear:			sta	($5e),y
			iny
			cpy	#40
			bcc	.clear
			ldx	752
			bne	.nocurs3
			lda	#$80
			ldy	$55
			sta	($5e),y
.nocurs3:		lda	#0
			sta	$5d
			lda	$5e
			clc
			adc	$55
			sta	$5e
			lda	$5e+1
			adc	#0
			sta	$5e+1
			rts
.get_adr:		lda	$54
			asl
			tay
			lda	$58
			clc
			adc	scr_offset,y
			sta	$5e
			lda	$58+1
			adc	scr_offset+1,y
			sta	$5e+1
			lda	$5e
			clc
			adc	$55
			sta	$5e
			lda	$5e+1
			adc	#0
			sta	$5e+1
			rts
.char_table:
			dc.b	27,28,29,30,31,125,126,127
			dc.b	156,157,158,159,253,254,255,0


putlocal:		ldx	#11
			stx	$0342
			ldx	#0
			stx	$0348
			stx	$0349
			jmp	ciov
;
;
;
program_name:
;
statline:
			dc.b	  <internal>, "                                        "
;
rw_screen:
			dc.b	  <internal>, ""
			dc.b	  <internal>, "|line 2                                |"
			dc.b	  <internal>, "|line 3                                |"
			dc.b	  <internal>, ""
			dc.b	  <internal>, ""
			dc.b	  <internal>, ">Press START to Load OPTION to Abort!<"
;
rw_screen_end:
;
;
cr_lf:			lda	#$9b

echo:
sprint:
			jmp	fast_output
;------------------------------
;   GET KEY  ROUTEEN           
;this routeen get's one key and
;return it to the accumlator   
;------------------------------
;
get_key:		stx	$b6
			sty	$b7
			jsr	g_fff
			ldx	$b6
			ldy	$b7
			rts


g_fff:			lda	$e420+5
			pha
			lda	$e420+4
			pha
			rts
;
;
;
;
;
;

ram_to_rom_end:
;
;----------------------------
;crc os test
;
;
;------------------------------
;
;
bad_crc:		dc.b	0
;
test_crc_:		dc.b	0
;
; checksum in os low
c000:			dc.w	0
;
; checksum in os  lsb/msb
fff8:			dc.w	0			;Checksum
;
;
; real checksum low
real_crc:		dc.w	0
;
; real checksum  high
real_crc1:		dc.w	0
;
ref_low_crc:		dc.w	0
;
ref_high_crc:		dc.w	0
;
ref_crc_low:		dc.w	0
;
ref_crc_high:		dc.w	0
;
;
;
crc_rom:
			pop_word	os,ref_low_crc
			mea	os,ref_crc_low
			pop_word	os+$3ff8,ref_high_crc
			mea	os+$3ff8,ref_crc_high
			mea	ffd7,lc_tab+1
			lda	#$00
			sta	test_crc_
			jmp	crc_start
;
crc_ram:
			pop_word	memory,ref_low_crc
			mea	memory,ref_crc_low
			pop_word	memory+$3ff8,ref_high_crc
			mea	memory+$3ff8,ref_crc_high
			mea	c_ffd7,lc_tab+1
			lda	#$01
			sta	test_crc_
;
crc_start:
			jsr	printsi
			dc.b	$7d,$9b,$9b
			dc.b	" OS Checksum Test program. Testing",$9B
			dc.b	" Checksum in the Smart OS.",$9B,$9B
			dc.b	" Checksum Results ",-1
			lda	#$00
			sta	bad_crc
			sta	helpfg
;    MEA  FFD7,LC_TAB+1
			lda	test_crc_
			cmp	#$00
			bne	damn
			lda	portb
			and	#$7f
			sta	portb
;
damn:
			jsr	csum_lo
			bcc	.next
			lda	#$ff
			sta	bad_crc
;
.next:
			jsr	csum_hi
			bcc	itok
bad:			lda	#$ff
			sta	bad_crc
itok:
			lda	test_crc_
			cmp	#$00
			bne	dam
			lda	portb
			ora	#$80
			sta	portb
dam:
			jsr	show_all
			jsr	clear_help
			rts
;
;-----------------
;
csum_lo:		ldx	#0			;ROM checksum verify routines
			stx	i.crc_ptr		;for 1st 8-k bank.
			stx	i.crc_ptr+1
d.cl1:			jsr	d.ch1
			cpx	#$0c
			bne	d.cl1
			jsr	mark_crc
			lda	ref_low_crc		;    OS
			sta	c000
			ldx	ref_low_crc+1		;  OS+1
			stx	c000+1
d.cl2:			cmp	i.crc_ptr
			bne	d.badrom
			cpx	i.crc_ptr+1
			bne	d.badrom
			clc
			rts
;
d.badrom:		sec         ;ROM doesn't check out.
			rts
mark_crc:
			lda	i.crc_ptr
			sta	real_crc
			lda	i.crc_ptr+1
			sta	real_crc+1
			rts
;-----------------------
mark_crc1:
			lda	i.crc_ptr
			sta	real_crc1
			lda	i.crc_ptr+1
			sta	real_crc1+1
			rts
;-----------------
;
csum_hi:		ldx	#0			;Verify routines for ROM checksum
			stx	i.crc_ptr		;2nd 8-k bank, including routines
			stx	i.crc_ptr+1		;to examine checksum region and
			ldx	#$0c			;table of addresses to verify.
			jsr	d.ch1
			jsr	d.ch1
			jsr	mark_crc1
			lda	ref_high_crc ; $FFF8
			sta	fff8
			ldx	ref_high_crc+1 ;$FFF8+1
			stx	fff8+1
			jmp	d.cl2
;
d.ch1:			ldy	#0			;Move start and end adresses
lc_tab:
d.ch2:			lda	ffd7,x			;for checksum routine to
			sta	i.c_ptr,y
			inx
			iny
			cpy	#4
			bne	d.ch2
			ldy	#0			;Start adding bytes.
d.ch3:			clc				;Result of addition will be 2-byte
			lda	(i.c_ptr),y		;number dc.w at i.crc_ptr.
			adc	i.crc_ptr		;Do the addition.
			sta	i.crc_ptr
			bcc	d.ch4
			inc	i.crc_ptr+1
d.ch4:			inc	i.c_ptr			;Increment address pointer.
			bne	d.ch5
			inc	$9f
d.ch5:			lda	i.c_ptr			;See if we are to the ending
			cmp	$a0			;address yet.
			bne	d.ch3
			lda	$9f
			cmp	$a1
			bne	d.ch3
			rts
;-----------------


;
c_ffd7:			dc.w	$4002,$5000
			dc.w	$5000,$5800
			dc.w	$5800,$6000
			dc.w	$6000,$7ff8
			dc.w	$7ffa,$8000
;
;
;Table of start and end addresses for the
;the checksum routines above.
;
ffd7:			dc.w	$c002,$d000
			dc.w	$5000,$5800
			dc.w	$d800,$e000
			dc.w	$e000,$fff8
			dc.w	$fffa,$00
;
;
show_all:
			lda	bad_crc
			cmp	#$ff
			beq	A1
			jsr	printsi
			dc.b	" OK!",$9B,-1
			jmp	A2
;
A1:
			jsr	printsi
			dc.b	" Failed!",$9B,-1
;
A2:
			jsr	printsi
			dc.b	$9b,"  $",-1
			show_hex_word	ref_crc_low
			jsr	printsi
			dc.b	" = $",-1
			show_hex_word	c000
			jsr	printsi
			dc.b	 " calc = $",-1
			show_hex_word	real_crc
			jsr	printsi
			dc.b	$9b,"  $",-1
			show_hex_word	ref_crc_high
			jsr	printsi
 			dc.b	" = $",-1
			show_hex_word	fff8
			jsr	printsi
			dc.b	 " calc = $",-1
			show_hex_word	real_crc1
			jsr	printsi
			dc.b	$9b,$9b,-1
			jsr	crc_menu
			rts
;
place_crc:
			php
			sei
			lda	nmien
			pha
			lda	#$00
			sta	nmien
			jsr	load_2
;
			lda	# high memory
			cmp	ref_crc_low+1
			beq	plc_crc
;
;
			lda	#os_ram+os_write
			jsr	control_line
			pop_word	real_crc,os
			pop_word	real_crc1,os+$3ff8
;
; Must make sure to enable the
; same os we are running!!
			lda	smos_data
			jsr	control_line
			jmp	plc_show
;
plc_crc:
			pop_word	real_crc,memory
			pop_word	real_crc1,memory+$3ff8
;
;
plc_show:
			pla
			sta	nmien
			plp
			jsr	restore_2
			cli
			jsr	my_wait
;
			jsr	printsi
			dc.b	$9b,$9b," Checksum's Installed!",$9B,$9B,-1
			rts
;
;-------------------------------
; Calculate all os crc's
;
;-------------------------------
;
do_all_crc:
			lda	smos_data
			cmp	#$00
			bne	sst
			rts
sst:
			lda	#$00
			sta	test_crc_
			php
;
			lda	nmien
			pha
			lda	#$00
			sta	nmien
			sei
			jsr	load_2
;
			jsr	printsi
			dc.b	$9b,"Calculating in use OS Checksum",$9B,-1
;
			pop_word	memory,ref_low_crc
			mea	memory,ref_crc_low
			pop_word	memory+$3ff8,ref_high_crc
			mea	memory+$3ff8,ref_crc_high
			mea	c_ffd7,lc_tab+1
;   JSR OS_ON
			jsr	rom_to_ram
			jsr	do_csum
;   JSR OS_OFF
;   JSR OS_CONTROL
			pop_dword	real_crc,current_os
			jsr	printsi
			dc.b	" $",-1
			show_hex_word	current_os
			jsr	printsi
			dc.b	" $",-1
			show_hex_word	current_os+2
;
			jsr	printsi
			dc.b	$9b,"Calculating RAM 1 OS",$9B,-1
;
			lda	#os_ram1
			jsr	control_line
			jsr	rom_to_ram
			jsr	os_control
			jsr	do_csum
			pop_dword	real_crc,ram1_os
			jsr	printsi
			dc.b	" $",-1
			show_hex_word	ram1_os
			jsr	printsi
			dc.b	" $",-1
			show_hex_word	ram1_os+2
;
			jsr	printsi
			dc.b	$9b,"Calculating RAM OS",$9B,-1
			lda	#os_ram
			jsr	control_line
			jsr	rom_to_ram
			jsr	os_control
			jsr	do_csum
			pop_dword	real_crc,ram_os
			jsr	printsi
			dc.b	" $",-1
			show_hex_word	ram_os
			jsr	printsi
			dc.b	" $",-1
			show_hex_word	ram_os+2
;
			jsr	printsi
			dc.b	$9b,"Calculating ROM OS",$9B,-1
			lda	#os_rom
			jsr	control_line
			jsr	rom_to_ram
			jsr	os_control
			jsr	do_csum
			pop_dword	real_crc,rom_os
			jsr	printsi
			dc.b	" $",-1
			show_hex_word	rom_os
			jsr	printsi
			dc.b	" $",-1
			show_hex_word	rom_os+2
;
;
;
			ldy	#0
c1_rom:			lda	current_os,y
			cmp	rom_os,y
			bne	c2_ram
			iny
			cpy	#4
			bne	c1_rom
			lda	#os_rom
			sta	rw_control
			sta	smos_data ; ADDED
			jsr	control_line
			mea	smosrom,sm_cfg
			jmp	gql
;
c2_ram:			ldy	#$00
c2_ram1:		lda	current_os,y
			cmp	ram1_os,y
			bne	c3_ram
			iny
			cpy	#4
			bne	c2_ram1
			lda	#os_ram1
			sta	rw_control
			sta	smos_data
			jsr	control_line
			mea	smosram1,sm_cfg
;   JMP GQL
c3_ram:			ldy	#$00
c3_ram1:		lda	current_os,y
			cmp	ram_os,y
			bne	c4_no
			iny
			cpy	#4
			bne	c3_ram1
;
c4_no:
			lda	#os_ram
			sta	rw_control
			sta	smos_data
			jsr	control_line
			mea	smosram,sm_cfg
;
gql:
			lda	smos_data
			sta	rw_control
			pla
			sta	nmien
			plp
			jsr	restore_2
			cli
			jsr	my_wait
			jsr	printsi
			dc.b	$9b,"  Done!",-1
			rts
;
;
;
;
;
;
;
;
do_csum:
			jsr	csum_lo
			jsr	csum_hi
			rts
;
os_on:
			lda	portb
			and	#$7f
			sta	portb
			rts
;
os_off:
			lda	portb
			ora	#$80
			sta	portb
			rts
;
os_control:
			lda	smos_data ; #OS_RAM
			jmp	control_line
;
;
pause:
			lda	#$ff
			sta	ch
			jsr	printsi
			dc.b	$9b,$9b," Press any key to continue!",-1
			jsr	get_key
			lda	#$9b
			jmp	echo
;
clear_help:
			lda	#$00
			sta	helpfg
			rts
;
help_screen:
			jsr	clear_help
;
			lda	#$00
			sta	$52     ; Left margin
;
			jsr	printsi
			dc.b	$7d,$9b,$9b
			dc.b	" It is very Important that you are Sure",$9B
			dc.b	" That the OS that you have loaded",$9B
			dc.b	" Conforms to the ATARI way of",$9B
			dc.b	" calculating the checksum for the OS.",$9B,$9B
			dc.b	" This program will Check the Checksum",$9B
			dc.b	" and will tell you if it is ok!.",$9B,$9B
			dc.b	" Please be aware that no all OS use",$9B
			dc.b	" the Checksum the same way. So Please",$9B
			dc.b	" Be carefull.  Have Fun.",$9B
			dc.b	$9b," Stephen J. Carden",$9B
			dc.b	" 3321 Jonathan Cir.",$9B
			dc.b	" Augusta, Ga. 30906",$9B,-1
			jsr	pause
			lda	#$02
			sta	$52
			lda	#$9b
			jsr	echo
			rts
;
;
crc_menu:
			lda	#$ff
			sta	ch
			jsr	printsi
			dc.b	$9b," Press SELECT to install Checksum",$9B
			dc.b	" Press Help for more info!",$9B
			dc.b	" Press Any KEY for Main Menu!",$9B,$9B,-1
;
.Aaa:
			lda	consol
			cmp	#$05
			beq	.go_crc
;   LDA CH
;   CMP #$0C
;   BEQ ?GO_CRC
			lda	helpfg
			cmp	#$00
			bne	.go_help
			lda	ch
			cmp	#$ff
			beq	.Aaa
			lda	#$ff
			sta	ch
			rts
;
.go_crc:		jmp	place_crc
.go_help:		jmp	help_screen
;
;
;
bank_purge:
			lda	#$40
			sta	mem_loop+2
purge_mem:
			ldy	#$00
			lda	#$00
mem_loop:
			sta	memory,y
			iny
			cpy	#$00
			bne	mem_loop
			inc	mem_loop+2
			lda	mem_loop+2
			cmp	#$7f+1
			bne	purge_mem
			rts
;
bbmenu:
			sei
			lda	#2
			sta	$d1c0
			ldy	#$10
y7008:
			ldx	#2
			lda	$d800,y
			cmp	y703b,x
			beq	y7016
			iny
			bne	y7008
			rts
;
y7016:
			iny
			dex
			bmi	y7024
			lda	$d800,y
			cmp	y703b,x
			bne	y7008
			beq	y7016
y7024:
			dey
			sty	y7031+1
			lda	# high y7033
			pha
			lda	# low y7033
			pha
			pha
			lda	#$ff
y7031:			jmp	$d800
;
y7033:
			cld
			lda	#0
			sta	$d1c0
			cli
			rts
;
y703b:			dc.b	$d0,$08,$29,$00
;
;
my_wait:
			lda	$14
.AAa:			cmp	$14
			beq	.AAa
			rts
;
;
test_smartos:
;
			lda	#os_ram
			sta	smos_data
			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	#os_rom
			sta	smos_data
;
not_in_rom:
			lda	#os_ram+os_write
			jsr	control_line
			lda	#$ff
			sta	$e000
			lda	$e000
			cmp	#$ff
			beq	smos_here
;
			pla
			sta	nmien
			plp
			lda	smos_data+1
			sta	portb
			cli
			lda	#$00
			sta	smos_data
			mea	smosnot,sm_cfg
			rts
;
smos_here:
			lda	#$00
			sta	$e000
			lda	smos_data
			jsr	control_line
;
			pla
			sta	nmien
			plp
			lda	smos_data+1
			sta	portb
			cli
;
			jsr	my_wait
;
			lda	smos_data
			cmp	#os_rom
			bne	Anot_in_rom
			mea	smosrom,sm_cfg
			rts
;
Anot_in_rom:
			lda	smos_data
			cmp	#os_ram
			bne	Anot_in_ram
			mea	smosram,sm_cfg
Anot_in_ram:
			rts
;
;
;
;
;
;
;
test_os:
			lda	$cffe
			cmp	#$10    ; xl os detected
			bne	Ausp1
			mea	xl_os,os_type
			rts
;
Ausp1:
			cmp	#$fe    ; turboss detected
			bne	Ausp2
			mea	i.turboss,os_type
			rts
;
Ausp2:
			cmp	#$90    ; Mux
			bne	Ausp3
			mea	mux_os,os_type
			rts
;
Ausp3:
			cmp	#$88    ; usp
			bne	Ausp4
			mea	usp_os,os_type
			rts
;
Ausp4:
;
			cmp	#$00    ; omnimon
			bne	Ausp5
			ldy	$cda5
			cpy	#$60
			beq	tbplus
;
			mea	omnimon,os_type
			rts
;
tbplus:
			mea	i.turboss_p,os_type
			rts
;
Ausp5:
;
			cmp	#$07    ; omniview
			bne	Ausp6
			mea	omniview,os_type
			rts
Ausp6:
			rts
;
;
;
;
;
;
;
make_os:
			jsr	printsi
			dc.b	$7d,$9b,$9b
			dc.b	<+128>,"[1]"
			dc.b	" SmartOS Boot ram!",$9B
			dc.b	<+128>,"[2]"
			dc.b	" SmartOS Aux Ram!",$9B
			dc.b	<+128>,"[E]"
			dc.b	"xit",$9B,$9B," Selection ",-1
			jsr	get_key
			jsr	locase
;
			cmp	#'1'
			beq	kk1
			cmp	#'2'
			beq	kk2
			cmp	#'e'
			beq	kk3
			jmp	make_os
;
kk3:			rts


kk1:			lda #os_ram
			dc.b	$2c
kk2:			lda #os_ram1
			sta	rw_control
;
;
;
kk4:
			ldx	#disk_2
			jsr	close
;
			mea	os_name,i.fn_ptr
			jsr	statbox
			ldx	#disk_2
			lda	#3
			sta	iccom,x
			lda	i.fn_ptr  ; # low OS_NAME
			sta	icbal,x
			lda	i.fn_ptr+1 ;# high OS_NAME
			sta	icbah,x
			lda	#8
			sta	icax1,x
			lda	#0
			sta	icax2,x
			jsr	ciov
;
			ldx	#disk_2
			lda	#$0b
			sta	iccom,x
			l_cio	load_os,ram_to_rom_end-load_os
			jsr	ciov
			l_cio	os_seg,4
			jsr	ciov
			l_cio	memory,os_l
			jsr	ciov
			l_cio	run_os,6
			jsr	ciov
;
			ldx	#disk_2
			jsr	close
			lda	smos_data
			jsr	control_line
			rts
;
;
;
prg_start:		dc.w	A_start
prg_end:		dc.w	A_end
prg_length:		dc.w	A_end-A_start
prg_s_start:		dc.w	$8000
prg_s_end:		dc.w	AA_end
prg_s_length:		dc.w	AA_end-$8000
;
;----------------------------
;
; $80 = Ram
; $40 = Rom
; $00 = Smartos Not Present!
smos_data:		dc.b	0,0,0
;
;
;OS check sum calculated atari's
; way!
current_os:		dc.w	0,0
rom_os:			dc.w	0,0
ram_os:			dc.w	0,0
ram1_os:		dc.w	0,0
;
;
z_200_save:
			dc.w	0,0,0,0,0,0,0,0
			dc.w	0,0,0,0,0,0,0,0
			dc.w	0,0,0,0,0,0
;
l_200_load:
;
; vdslst $200
			dc.w	d_list
;
; vprced  $202
			dc.w	junk_entry
;
; vinter  $204
			dc.w	junk_entry
;
; vbreak $206
			dc.w	junk_entry
;
; vkeybd  $208
			dc.w	junk_entry
;
; vserin  $20a
			dc.w	junk_entry
;
; vseror $20c
			dc.w	junk_entry
;
; vseroc  $20e
			dc.w	junk_entry
;
; vtimr1 $210
			dc.w	junk_entry
;
; vtimr2 $212
			dc.w	junk_entry
;
;vtimr4 $214
			dc.w	junk_entry
;
; vimirq $216
			dc.w	junk_entry
;
;  cdtmv1  $218
			dc.w	0
;
;  cdtmv2 $21a
			dc.w	0
;
;  cdtmv3  $21c
			dc.w	0
;
;  cdtmv4  $21e
			dc.w	0
;
; cdtmv5   $220
			dc.w	0
;
; vvblki   $222
			dc.w	junk_entry
;
; vvblkd   $224
			dc.w	junk_entry
;
; cdtma1
			dc.w	0			;$226
;
; cdtma2
			dc.w	0			;$228
;
;
junk_entry:
			pla
			rti
;
;
;
load_2:
			ldy	#$00
.AAA:			lda	$200,y
			sta	z_200_save,y
			lda	l_200_load,y
			sta	$0200,y
			iny
			cpy	#41
			bne	.AAA
			rts
;
restore_2:
			ldy	#$00
A.A:			lda	z_200_save,y
			sta	$0200,y
			iny
			cpy	#41
			bne	A.A
			rts
;
kathy_m:
			dc.w	$ffff
			dc.w	memory
			dc.w	memory+os_l
;
kathy_bob:
			dc.w	$ffff
			dc.w	0
			dc.w	os_l
;
;----------------------------
; 0 = pro burner
; 1 = bob burner
; 2 = ibm pc image file
;
burner_type:		dc.b	0
;
steve_os:
;
			jsr	printsi
			dc.b	$7d,$9b,$9b
			dc.b	<+128>,"[E]"
			dc.b	"xit",$9B
			dc.b	<+128>,"[P]"
			dc.b	"ro Burner file!",$9B
			dc.b	<+128>,"[B]"
			dc.b	"ob Burner file!",$9B
			dc.b	<+128>,"[I]"
			dc.b	"BM PC image file!",$9B,$9B
			dc.b	"   Selection ",-1
;
			jsr	get_key
			jsr	locase
			cmp	#'e'
			beq	wr_exit
			cmp	#'p'
			beq	wr_pro
			cmp	#'b'
			beq	wr_bob
			cmp	#'i'
			beq	wr_ibm
			jmp	steve_os
;
wr_exit:		rts




wr_pro:			lda	#$00
			dc.b	$2c
wr_bob:			lda	#$01
			dc.b	$2c
wr_ibm:			lda	#$02
			sta	burner_type
;
wri_st:
			ldx	#disk_2
			jsr	close
			mea	os_name,i.fn_ptr
			jsr	file_stat
			jsr	statbox
			ldx	#disk_2
			lda	#3
			sta	iccom,x
			lda	i.fn_ptr  ; # low OS_NAME
			sta	icbal,x
			lda	i.fn_ptr+1 ;# high OS_NAME
			sta	icbah,x
			lda	#8
			sta	icax1,x
			lda	#0
			sta	icax2,x
			jsr	ciov
;
			ldx	#disk_2
			lda	#$0b
			sta	iccom,x
;
			lda	burner_type
			cmp	#$02
			beq	gpc1
;
			cmp	#$01
			beq	gpc2
			cmp	#$00
			beq	gpc3
			ldx	#disk_2
			jmp	close
;
gpc3:
			l_cio	kathy_m,6
			jmp	gpc
gpc2:
			l_cio	kathy_bob,6
gpc:
			jsr	ciov
;
gpc1:
			l_cio	memory,os_l
			jsr	ciov
;
			ldx	#disk_2
			jsr	close
			lda	smos_data
			jsr	control_line
			rts
;
;
;------------------------------
;
;CHANEL NUMBER GETS
;LOADED INTO THE X REGISTER FILE
;PARM'S ARE LOADED LOW BYTE INTO
;i.fn_ptr HIGH BYTE i.fn_ptr+1 THEN A JSR
;TO THE LABLE YOU WISH TO OPEN BY
;
OPENIN
			lda	#4
			dc.b	$2C
OPENOUT
			lda	#8
			dc.b	$2C
OPENAPP
			lda	#9
			dc.b	$2C
OPENUPDT
			lda	#12
			dc.b	$2C
OPENDIR
			lda	#6
			dc.b	$2C
OPENRAW
			lda	#20
			jmp	OPEN_WORK
;
GET
			lda	#$05
			sta	ICCOM,X
			lda	i.pr_ptr
			sta	ICBAL,X
			lda	i.pr_ptr+1
			sta	ICBAH,X
			lda	LNPTR
			sta	ICBLL,X
			lda	LNPTR+1
			sta	ICBLH,X
			lda	#$03
			sta	ICAX1,X
			lda	#128
			sta	ICAX2,X
			jmp	CIOV
;
;
;           XIO 45
BOOT:     
			jsr	XIO_CLEAR
			lda	#$26
			jmp	OPEN_WORK
;
;
STATUS1:		dc.b	$00
STATUS:
			sta	STATUS1
			jsr	XIO_CLEAR
			lda	STATUS1
			sta	ICAX1,X
			lda	#$0D
			jmp	XIO_WORK
;
XIO_CLEAR:
			lda	#$00
			sta	i.pr_ptr
			sta	i.pr_ptr+1
			sta	LNPTR
			sta	LNPTR+1
			rts 
;
OPEN_WORK:
			sta	ICAX1,X
			lda	#$03
			sta	ICCOM,X
			lda	i.fn_ptr
			sta	ICBAL,X
			lda	i.fn_ptr+1
			sta	ICBAH,X
			lda	#128
			sta	ICBLL,X
			lda	#0
			sta	ICBLH,X
			lda	#128
			sta	ICAX2,X
			jmp	CIOV
;
;------------------------------
;you must jsr to this vector for point, note, file lenght
;
PNFDATA:		dc.b	"Dx:",$00
PNFDATA1:		dc.b	$00,$00
PNF_WORK:
			STX	PNFDATA1
			lda	i.fn_ptr
			sta	PNF_1+1
			lda	i.fn_ptr+1
			sta	PNF_1+2
			sty	PNFDATA1+1
			ldy	#$01
PNF_1:			LDA	$FFFF,Y
			sta	PNFDATA+1
			ldy	PNFDATA1+1
			ldx	PNFDATA1
			lda	#$00
			sta	ICAX1,X
			lda	#$00
			sta	ICAX2,X
			lda	# low PNFDATA
			sta	ICBAL,X
			lda	# high PNFDATA
			sta	ICBAH,X
			jmp	CIOV
;
;           XIO #32 RENAME FILE
RENAME:   
			lda	#$20
			jsr	XIO_WORK
			rts
;
;           XIO #33 ERASE FILE'S
ERASE:    
			jsr	XIO_CLEAR
			lda	#$21
			jsr	XIO_WORK
			rts
;
;           XIO #34 LOCK DISKETTE
LOCK:     
			jsr	XIO_CLEAR
			lda	#$22
			jsr	XIO_WORK
			rts
;
;           XIO #35  PROTECT FILE'S
PROTECT:  
			jsr	XIO_CLEAR
			lda	#$23
			jsr	XIO_WORK
			rts
;
;
;          XIO #36 UNPROTECT FILE'S
UNPROTECT: 
			jsr	XIO_CLEAR
			lda	#$24
			jsr	XIO_WORK
			rts
;
;           XIO 37  POINT
POINT:    
			lda	#$25
			STX	XIO_39_HOLD
			sta	ICCOM,X
			lda	OFFSET
			sta	$034C,X
			lda	i.SECTOR
			sta	$034D,X
			lda	i.SECTOR+1
			sta	$034E,X
			jsr	PNF_WORK
			ldx	XIO_39_HOLD
			RTS 


i.SECTOR:		dc.w	0
OFFSET:			dc.b	0


;
;
;           XIO_38  NOTE
NOTE:     
			STX	XIO_39_HOLD
			lda	#$26
			sta	ICCOM,X
			jsr	PNF_WORK
			ldx	XIO_39_HOLD
			lda	$034C,X
			sta	OFFSET
			lda	$034D,X
			sta	i.SECTOR
			lda	$034E,X
			sta	i.SECTOR+1
XIO_38E:		RTS

 
NPSAVE1:  dc.b 0,0,0

NPSAVE:
			lda	OFFSET
			sta	NPSAVE1
			lda	i.SECTOR
			sta	NPSAVE1+1
			lda	i.SECTOR+1
			sta	NPSAVE1+2
			RTS 
NPLOAD:
			lda	NPSAVE1
			sta	OFFSET
			lda	NPSAVE1+1
			sta	i.SECTOR
			lda	NPSAVE1+2
			sta	i.SECTOR+1
			RTS 
;
;
;
;           XIO#39 FILE LENGTH SPARTA ONLY
F_LENGTH: 
			STX	XIO_39_HOLD
			lda	#$27
			sta	ICCOM,X
			jsr	PNF_WORK
			ldx	XIO_39_HOLD
			lda	$034C,X
			sta	FNLNG
			sta	F_LNG
			lda	$034D,X
			sta	FNLNG+1
			sta	F_LNG+1
			lda	$034E,X
			sta	FNLNG+2
			sta	F_LNG+2
			RTS 


XIO_39_HOLD:		dc.b	0,0
FNLNG:			dc.b	0,0,0
F_LNG:			dc.b	0,0,0
;i.fn_ptr:		dc.w	0
LNPTR:			dc.w	0
;
;
;
;           AND RUN _XIO_40_
BLOAD:    
			lda	#$28
			jsr	XIO_WORK
			rts
;
;           AND APPEND _XIO_41_
BSAVE:    
			lda	#$29
			jsr	XIO_WORK
			rts
;
;
;           XIO_42
CREDIR:   
			jsr	XIO_CLEAR
			lda	#$2A
			jsr	XIO_WORK
			rts
;
;           XIO_43
DELDIR:   
			jsr	XIO_CLEAR
			lda	#$2B
			jsr	XIO_WORK
			rts
;
;           [C]hange [W]orking [D]ir
CWD:      
; XIO_44
			lda	#$2C
			jsr	XIO_WORK
			rts
;
;           XIO 47 CHECK DISK
CHKDSK:   
			lda	i.pr_ptr
			sta	ICBLL,X
			lda	i.pr_ptr+1
			sta	ICBLH,X
;
			lda	#$2F
			jsr	XIO_WORK
			rts
;
;
;       ?DIR XIO 48
GET_DIR_PATH: 
			lda	i.pr_ptr
			sta	ICBLL,X
			lda	i.pr_ptr+1
			sta	ICBLH,X
;
			lda	#$30
			jsr	XIO_WORK
			rts
;
;
;
XIO_WORK:
			sta	ICCOM,X
			lda	#$04
			sta	ICAX1,X
			lda	#$7F			; WAS 128
			sta	ICAX2,X
			lda	i.fn_ptr
			sta	ICBAL,X
			lda	i.fn_ptr+1
			sta	ICBAH,X
			jmp	CIOV
;
;----------------------------;
; LDA i.pr_ptr ; BUFFER
; STA #<BUFFER+1
;
BGET:
			lda	#$07
			sta	ICCOM,X
			lda	i.pr_ptr
			sta	ICBAL,X
			lda	i.pr_ptr+1
			sta	ICBAH,X
			lda	LNPTR
			sta	ICBLL,X
			lda	LNPTR+1
			sta	ICBLH,X
			lda	#$03
			sta	ICAX1,X
			lda	#$00
			sta	ICAX2,X
			jmp	CIOV
;---------------------
;  i.pr_ptr=BUFFER 
; i.fn_ptr=LEINGTH OF BUFFER
;---------------------
BPUT:
			lda	#$0B
			sta	ICCOM,X
			lda	i.pr_ptr
			sta	ICBAL,X
			lda	i.pr_ptr+1
			sta	ICBAH,X
			lda	LNPTR
			sta	ICBLL,X
			lda	LNPTR+1
			sta	ICBLH,X
			lda	#$03
			sta	ICAX1,X
			lda	#$00
			sta	ICAX2,X
C_IOV:
			jsr	CIOV
			lda	$0303
			TAY 
			cpy	#$81
			bcc	C_IOV_EXIT
			jmp	DRIVERROR
C_IOV_EXIT:
			RTS 
;
DRIVERROR:
			PHA 
			jsr	PRINTSI
			dc.b	$9B," Ciov Error # ",$FF
			PLA 
			jsr	PR_BYTE
			jsr	CR_LF
			jmp	PAUSE
;

;---------------------------------------------------------
;
;
;
usp_mem_layout:
total_banks:		dc.b	0
bank_0:			dc.b	0
bank_1:			dc.b	0
bank_2:			dc.b	0
bank_3:			dc.b	0
bank_4:			dc.b	0
bank_5:			dc.b	0
bank_6:			dc.b	0
bank_7:			dc.b	0
bank_8:			dc.b	0
bank_9:			dc.b	0
bank_10:		dc.b	0
bank_11:		dc.b	0
bank_12:		dc.b	0
bank_13:		dc.b	0
bank_14:		dc.b	0
bank_15:		dc.b	0
bank_16:		dc.b	0
bank_17:		dc.b	0
bank_18:		dc.b	0
bank_19:		dc.b	0
bank_20:		dc.b	0
bank_21:		dc.b	0
bank_22:		dc.b	0
bank_23:		dc.b	0
bank_24:		dc.b	0
bank_25:		dc.b	0
bank_26:		dc.b	0
bank_27:		dc.b	0
bank_28:		dc.b	0
bank_29:		dc.b	0
bank_30:		dc.b	0
bank_31:		dc.b	0
bank_32:		dc.b	0
bank_33:		dc.b	0
bank_34:		dc.b	0
bank_35:		dc.b	0
bank_36:		dc.b	0
bank_37:		dc.b	0
bank_38:		dc.b	0
bank_39:		dc.b	0
bank_40:		dc.b	0
bank_41:		dc.b	0
bank_42:		dc.b	0
bank_43:		dc.b	0
bank_44:		dc.b	0
bank_45:		dc.b	0
bank_46:		dc.b	0
bank_47:		dc.b	0
bank_48:		dc.b	0
bank_49:		dc.b	0
bank_50:		dc.b	0
bank_51:		dc.b	0
bank_52:		dc.b	0
bank_53:		dc.b	0
bank_54:		dc.b	0
bank_55:		dc.b	0
bank_56:		dc.b	0
bank_57:		dc.b	0
bank_58:		dc.b	0
bank_59:		dc.b	0
bank_60:		dc.b	0
bank_61:		dc.b	0
bank_62:		dc.b	0
bank_63:		dc.b	0
bank_64:		dc.b	0
bank_65:		dc.b	0
bank_66:		dc.b	0
bank_67:		dc.b	0
bank_68:		dc.b	0
bank_69:		dc.b	0
bank_70:		dc.b	0
bank_71:		dc.b	0
bank_72:		dc.b	0
bank_73:		dc.b	0
bank_74:		dc.b	0
bank_75:		dc.b	0
bank_76:		dc.b	0
bank_77:		dc.b	0
bank_78:		dc.b	0
bank_79:		dc.b	0
bank_80:		dc.b	0
bank_81:		dc.b	0
bank_82:		dc.b	0
bank_83:		dc.b	0
bank_84:		dc.b	0
bank_85:		dc.b	0
bank_86:		dc.b	0
bank_87:		dc.b	0
bank_88:		dc.b	0
bank_89:		dc.b	0
bank_90:		dc.b	0
bank_91:		dc.b	0
bank_92:		dc.b	0
bank_93:		dc.b	0
bank_94:		dc.b	0
bank_95:		dc.b	0
bank_96:		dc.b	0
bank_97:		dc.b	0
bank_98:		dc.b	0
bank_99:		dc.b	0
bank_100		dc.b	0
bank_101		dc.b	0
bank_102		dc.b	0
bank_103		dc.b	0
bank_104		dc.b	0
bank_105		dc.b	0
bank_106		dc.b	0
bank_107		dc.b	0
bank_108		dc.b	0
bank_109		dc.b	0
bank_110		dc.b	0
bank_111		dc.b	0
bank_112		dc.b	0
bank_113		dc.b	0
bank_114		dc.b	0
bank_115		dc.b	0
bank_116		dc.b	0
bank_117		dc.b	0
bank_118		dc.b	0
bank_119		dc.b	0
bank_120		dc.b	0
bank_121		dc.b	0
bank_122		dc.b	0
bank_123		dc.b	0
bank_124		dc.b	0
bank_125		dc.b	0
bank_126		dc.b	0
bank_127		dc.b	0
bank_128		dc.b	0
;---------------------------
; Making the same layout
; that Bob Puff's USP uses
xor_byte:		dc.b	0
			dc.b	0,0,0
			dc.b	"Bob's OS 8"
ils_hold_d301:		dc.b	0,0,0,0,0,0,0,0,0,0
;
; drive layout table
drive_table:
			dc.b	1
			dc.b	2
			dc.b	3
			dc.b	4
			dc.b	5
			dc.b	6
			dc.b	7
			dc.b	8
			dc.b	9
			dc.b	10
;
			dc.b	0,0,0,0,0,0
			dc.b	$ff
			dc.b	0,0,0
			dc.b	"C. HAMLIN",$9B
			dc.b	$52,$50,$02
;
;
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
;
			dc.b	0,0,0,0,0,0,0,0
;
x_cart:			dc.b	0
;


;
master_d301		dc.b	0
;
;
hold_d301		dc.b	0
;
hold_banks		dc.b	0
;
bank_layout:
			dc.b	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
;
buf_1:			ds.b	256
;
buf_2:			ds.b	256
;
;
;
;
;
;
;
find_memory:
			sei
			ldy	#0
			sty	$d40e
			sty	$d20e
			lda	portb
			sta	hold_d301
			pha
			ldx	#$ff
.lop_1:			sty	portb
			lda	memory
			sta	buf_1,y
			stx	memory
			txa
			sta	buf_2,y
			iny
			bne	.lop_1
			dex
			stx	portb
			stx	$00
			stx	memory
			stx	$8000
			stx	os
			ldx	#0
.lop_2:			sty	portb
			lda	memory
			cmp	#$ff
			bne	.lop_3
			inx
			stx	memory
			txa
.lop_3:			sta	buf_2,y
			iny
			bne	.lop_2
			stx	hold_banks
			ldx	#1
.lop_4:			txa
			ldy	#$ff
.lop_5:			cmp	buf_2,y
			beq	.lop_7
			dey
			cpy	#$ff
			bne	.lop_5
			nop
.lop_6:			sty	portb
			lda	buf_1,y
			sta	memory
			dey
			cpy	#$ff
			bne	.lop_6
			pla
			sta	portb
			lda	#$c0
			sta	$d40e
			lda	$10
			sta	$d20e
			cli
			rts
;
.lop_7:			tya
			sta	bank_layout,x
			inx
			cpx	#128+1			;    65     ;$41
			bcc	.lop_4
			ldy	#$fe
			bne	.lop_6
;
mem_test:
			lda	portb
			sta	ils_hold_d301
			sta	master_d301
			lda	$0700
			cmp	#'R'
			beq	dav
			cmp	#'S'
			bne	dav
			lda	$0701
			cmp	#$40
			bcc	dav
			lda	#'X'
			sta	x_cart
;
dav:
			jsr	find_memory
			lda	bank_layout+1
			sta	hold_d301
			ldy	#$00
_h:			lda	bank_layout,y
			eor	hold_d301
			sta	usp_mem_layout,y
			iny
			cpy	hold_banks
			bcc	_h
			lda	bank_layout,y
			eor	hold_d301
			sta	usp_mem_layout,y
			lda	hold_banks
			sta	total_banks
			lda	hold_d301
			sta	xor_byte
;
			lda	consol
			cmp	#$07    ; select key
			beq	aims_out
			ldy	#128
aims:			lda	usp_mem_layout,y
			cmp	$d700,y
			bne	amy
			iny
			cpy	#$00
			bne	aims
;
aims_out:		rts
;
amy:			sty	usp_mem_layout
			lda	#$ff
			sta	usp_mem_layout+1
			rts
AA_end:

win_end:		ds.b	0
;
;
;