;------------------------------------------------------------------------
;		Copyright 2010 Integrated Logic Systems
;                  Source Code is Copyright Stephen J. Carden
;
;
;			Please do not share this source!
;------------------------------------------------------------------------
;                              CRCcheck.com
;
;	This is a program that does a 16 bit CRC that was embeded in the file
;	to verify that the com file has not had a single byte altered since
;	it was compiled and sent out.
;
;
;
;		init	2/24/2010	sjc new design
;		added hex delimeter 		2/25/2010	sjc		
;		added new code for registered user 2/26/2010	sjc
;	Updated the screen Print Utility so it will work with the exp-80
; This change will also help "Print P:"		6/19/2010	sjc
;
;Also added code for Control+1 pause of screen to the high speed screen
;handling.		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,"Crccheck.com",$9b
			.endm

;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; File revision history. Version Number in hex
;
file_ver:		equ   $14
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; 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   27
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; 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 our Header control Byte
;$ff =bypass intro
;$15 = Bypass Dos check
r..crl:			equ	$7d
r..crlf:		equ	$9b
r..space:		equ	$20
r..bypassDOS:		equ	$15
r..bypass:		equ	$ff
;
l_frstscreenbyte:	equ	r..space
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; The language the output file is in. 
;
;
; 0	=	Undifined
; 1	=	English
; 2	=	German
;
r..language:		equ	1
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

;
;
buff_l:			equ    $9fff-copy_buff
;


			.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
readcli:

			ldx	#$00
			ldy	#LBUF    			; loading the offset into comtab
.a:			lda	(comtab),y
			cmp	#' '				; looking for the space in the parm line
			beq	.gotspacechar 			; got the space let'S see if there is anything we can use
			cmp	#$9b				; nope!!  no parm
			beq	.noparmerror 			; let'S see if they are playing with the consol

			iny
			jmp	.a


.noparmerror:		jmp	usage_error	; based on info stored at the front of the file

.gotspacechar:		ldx	#$00

.lop:			iny
			inx
			lda	(comtab),y
			sta	parm_1,x
			stx	parm_1
			cmp	#$9b
			bne	.lop
			jmp	top

;
filename:
			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
			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
			dc.b	0,0,0,0,0,0,0,0,0,0
			dc.b	0,0,0,0,0,0,0,0,0,0
usage_error:
			jsr	printsi
			dc.b	$9b,$9b
			dc.b	"Syntax Error!"
			dc.b	$9b
			dc.b	"Usage: Crccheck Dn:>path>filename.ext"
			dc.b	$9b
			dc.b	$9b
			dc.b	-1
			rts

;
top:
;			lda	s_node
;			sta	d_node
;			lda	s_node+1
;			sta	d_node+1
;
;       Copy the file in source_path/source_file to dest_path/source_file
;       -----------------------------------------------------------------
copy_file:
;
			mea	parm_1,s_ptr
			mea	_infile,d_ptr
			jsr	toascii
			mea	_infile,fn_ptr
			ldx	#$20
			jsr	open_in
			bmi	_error
_srcok:


_copyloop:
			ldx	#$20
			jsr	blockread
			dc.w	copy_buff
			dc.w	buff_l
			bpl	_readok
			cpy	#136
			beq	_readok
_shutdown:		sty	_savey		;copy error - shut this
			ldx	#$20		; baby down right now__
			jsr	close
			ldy	_savey
			jmp	next_run
			rts
;
first_call:		dc.b 0
;
_readok:
			lda	first_call
			cmp	#$00
			bne	_.wer
			jsr	set_pass
			inc	first_call
;
_.wer:
			ldx	#$20
			lda	icbll,x
			sta	_totbytes
			lda	icblh,x
			sta	_totbytes+1
			jsr	wipe


			lda	_totbytes
			cmp	#buff_l & $ff		;did we read a full buffer?
			bne	_.done   		;nope, must be done!
			lda	_totbytes+1
			cmp	#buff_l / 256
			bne	_.done
			jmp	_copyloop
;
_totbytes:		dc.w	buff_l
_.done:			ldy	#1
			jmp	_shutdown
_idx:			dc.b	0
_savey:			dc.b	0
_error:			jmp	system_error
			
_infile:
			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
_outfile:
			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_1:			ds.b	80

;     Make an ASCII ($9b terminated) string out of a lth-byte string
;     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

toascii:        	ldy	#0
                	lda	(s_ptr),y               ;get lth byte
                	sta	.lth
                	beq     .null
                	iny
                	inc     .lth
.loop:          	lda	(s_ptr),y
                	dey
                	sta	(d_ptr),y
                	iny
                	iny
                	cpy	.lth
                	bne	.loop
.done:          	ldy	.lth
                	dey
.rtn:           	lda	#$9b
                	sta	(d_ptr),y
                	rts
.null:          	ldy	#0
                	beq	.rtn

.lth:			dc.b    1

;	Display error message of flag in Y register
;	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

system_error:		sty	.hold
			jsr	printsi
			dc.b	$9b,$9b
			dc.b	"System Error: ",-1
			lda	.hold
			jsr	pr_byte
			jsr	printsi
			dc.b	$9b,-1
			ldx	#$20
			jsr	close
			rts


.hold:			dc.b	0


;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;This creates an length byte string and then 
;prints it to the screen.	
;
;
;
pr_byte:
			ldx	#$00
pr_card:
			sta	fr0
			stx	fr0+1
			lda	#$00
			sta	cix
			sta	pr_data
			jsr	ifp
			jsr	fasc
			ldy	#$00
.loop:
			inc	pr_data
			lda	($f3),y
			php
			and	#$7f
			sta	pr_data+1,y
			iny
;			jsr	echo
			plp
			bpl	.loop
			mea	pr_data,pr_ptr
			jsr	echos
			rts

pr_data:		ds.b	10




;       Expand wildcarded name to create an output filename_
;       Input is source_file, dest_file; output is out_name_
;       ----------------------------------------------------
;
;
;
put256_out:
			ldy	#0
			sty	crc_sum
			sty	crc_sum+1
			sty	chk_sum
;
crc_loop:
			lda	(pr_ptr),y
			pha
			clc
			adc	chk_sum		;calc standard checksum
			sta	chk_sum
			pla
			eor	crc_sum+1	;now do the CRC checksum
			tax
			lda	crc_hitable,x
			eor	crc_sum
			sta	crc_sum+1
			lda	crc_lotable,x
			eor	#0
			sta	crc_sum
			rts
;
;
;
crc_lotable:
			dc.b	$00,$21,$42,$63,$84,$a5,$c6,$e7,$08,$29
			dc.b	$4a,$6b,$8c,$ad,$ce,$ef,$31,$10,$73,$52
			dc.b	$b5,$94,$f7,$d6,$39,$18,$7b,$5a,$bd,$9c
			dc.b	$ff,$de,$62,$43,$20,$01,$e6,$c7,$a4,$85
			dc.b	$6a,$4b,$28,$09,$ee,$cf,$ac,$8d,$53,$72
			dc.b	$11,$30,$d7,$f6,$95,$b4,$5b,$7a,$19,$38
			dc.b	$df,$fe,$9d,$bc,$c4,$e5,$86,$a7,$40,$61
			dc.b	$02,$23,$cc,$ed,$8e,$af,$48,$69,$0a,$2b
			dc.b	$f5,$d4,$b7,$96,$71,$50,$33,$12,$fd,$dc
			dc.b	$bf,$9e,$79,$58,$3b,$1a,$a6,$87,$e4,$c5
			dc.b	$22,$03,$60,$41,$ae,$8f,$ec,$cd,$2a,$0b
			dc.b	$68,$49,$97,$b6,$d5,$f4,$13,$32,$51,$70
			dc.b	$9f,$be,$dd,$fc,$1b,$3a,$59,$78,$88,$a9
			dc.b	$ca,$eb,$0c,$2d,$4e,$6f,$80,$a1,$c2,$e3
			dc.b	$04,$25,$46,$67,$b9,$98,$fb,$da,$3d,$1c
			dc.b	$7f,$5e,$b1,$90,$f3,$d2,$35,$14,$77,$56
			dc.b	$ea,$cb,$a8,$89,$6e,$4f,$2c,$0d,$e2,$c3
			dc.b	$a0,$81,$66,$47,$24,$05,$db,$fa,$99,$b8
			dc.b	$5f,$7e,$1d,$3c,$d3,$f2,$91,$b0,$57,$76
			dc.b	$15,$34,$4c,$6d,$0e,$2f,$c8,$e9,$8a,$ab
			dc.b	$44,$65,$06,$27,$c0,$e1,$82,$a3,$7d,$5c
			dc.b	$3f,$1e,$f9,$d8,$bb,$9a,$75,$54,$37,$16
			dc.b	$f1,$d0,$b3,$92,$2e,$0f,$6c,$4d,$aa,$8b
			dc.b	$e8,$c9,$26,$07,$64,$45,$a2,$83,$e0,$c1
			dc.b	$1f,$3e,$5d,$7c,$9b,$ba,$d9,$f8,$17,$36
			dc.b	$55,$74,$93,$b2,$d1,$f0
crc_hitable:
			dc.b	$00,$10,$20,$30,$40,$50,$60,$70,$81,$91,$a1,$b1,$c1
			dc.b	$d1,$e1,$f1,$12,$02,$32,$22,$52,$42,$72,$62,$93,$83
			dc.b	$b3,$a3,$d3,$c3,$f3,$e3,$24,$34,$04,$14,$64,$74,$44
			dc.b	$54,$a5,$b5,$85,$95,$e5,$f5,$c5,$d5,$36,$26,$16,$06
			dc.b	$76,$66,$56,$46,$b7,$a7,$97,$87,$f7,$e7,$d7,$c7,$48
			dc.b	$58,$68,$78,$08,$18,$28,$38,$c9,$d9,$e9,$f9,$89,$99
			dc.b	$a9,$b9,$5a,$4a,$7a,$6a,$1a,$0a,$3a,$2a,$db,$cb,$fb
			dc.b	$eb,$9b,$8b,$bb,$ab,$6c,$7c,$4c,$5c,$2c,$3c,$0c,$1c
			dc.b	$ed,$fd,$cd,$dd,$ad,$bd,$8d,$9d,$7e,$6e,$5e,$4e,$3e
			dc.b	$2e,$1e,$0e,$ff,$ef,$df,$cf,$bf,$af,$9f,$8f,$91,$81
			dc.b	$b1,$a1,$d1,$c1,$f1,$e1,$10,$00,$30,$20,$50,$40,$70
			dc.b	$60,$83,$93,$a3,$b3,$c3,$d3,$e3,$f3,$02,$12,$22,$32
			dc.b	$42,$52,$62,$72,$b5,$a5,$95,$85,$f5,$e5,$d5,$c5,$34
			dc.b	$24,$14,$04,$74,$64,$54,$44,$a7,$b7,$87,$97,$e7,$f7
			dc.b	$c7,$d7,$26,$36,$06,$16,$66,$76,$46,$56,$d9,$c9,$f9
			dc.b	$e9,$99,$89,$b9,$a9,$58,$48,$78,$68,$18,$08,$38,$28
			dc.b	$cb,$db,$eb,$fb,$8b,$9b,$ab,$bb,$4a,$5a,$6a,$7a,$0a
			dc.b	$1a,$2a,$3a,$fd,$ed,$dd,$cd,$bd,$ad,$9d,$8d,$7c,$6c
			dc.b	$5c,$4c,$3c,$2c,$1c,$0c,$ef,$ff,$cf,$df,$af,$bf,$8f
			dc.b	$9f,$6e,$7e,$4e,$5e,$2e,$3e,$0e,$1e
;
;
;
;
cksum_lo:		dc.b	0
cksum_hi:		dc.b	0
crcsize:		dc.w	0
crctemp:		dc.w	0
crc_sum:		dc.w	0
chk_sum:		dc.w	0
;
real_sum:		dc.w	0     ; real crc check sum
n_split:		dc.w	0     ; split of node number
n_split1:		dc.w	0     ; split of node number


;       Blockread from disk channel in X register.
;
;       call:   jsr     blockread
;                dc.w   buffer_address
;                dc.w   number_of_bytes
;       ------------------------------------------
;
;
blockread:		lda	#ccgetch
			sta	iccom,x
			jmp	blockio
blockwrite:		lda	#ccputch
			sta	iccom,x
			jmp	blockio
blockio:		pla
			sta	pr_ptr
			pla
			sta	pr_ptr+1
			inc	pr_ptr
			bne	Anovf
			inc	pr_ptr+1
Anovf:			ldy	#0
			lda	(pr_ptr),y
			sta	icbal,x
			iny
			lda	(pr_ptr),y
			sta	icbah,x
			iny
			lda	(pr_ptr),y
			sta	icbll,x
			iny
			lda	(pr_ptr),y
			sta	icblh,x
			lda	pr_ptr
			clc
			adc	#3
			sta	pr_ptr
			lda	pr_ptr+1
			adc	#0
			pha
			lda	pr_ptr
			pha
			lda	icbll,x		;make sure not requesting
			ora	icblh,x		; zero bytes!
			beq	Aoops
			jmp	ciov
Aoops:			ldy	#1      ;signal success and exit
			rts

;--------------------------------------------
;printsi Routeen macro             
;this is a slow print to the screen
;usage jsr	printsi
;    .byte $9b," string to be printed",$ff
;--------------------------------------------
;
sprintsi:		pla
			sta	$b0
			pla
			sta	$b1
			ldy	#$01
.a:			lda	($b0),y
			cmp	#$ff
			beq	.b
			jsr	sprint
			jsr	.c
			jmp	.a
.b:			jsr	.c
			lda	$b1
			pha
			lda	$b0
			pha
			rts
.c:			inc	$b0
			bne	.d
			inc	$b1
.d:			rts
;
; 
;--------------------------------------------
;printsi Routeen macro             
;this is a slow print to the screen
;usage jsr	printsi
;    .byte $9b," string to be printed",$ff
;--------------------------------------------
;
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


;
;------------
; PRINT BYTE 
;------------
echo
sprint:
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
			cpy	#24
			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	$e456
;

;-----------------------------
;    ERROR NUMBER             
;-----------------------------
;
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	d_error
			lda	h_cardd
			jsr	d_error
			rts
;
;
d_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	echo
			rts



;ff ff 00 00 00 00 4c ff ff	
; ver month day year 0 0
set_pass:
			lda	irf.c_crc		;fixed this
			sta	inst_crc
			lda	irf.c_crc+1
			sta	inst_crc+1
			lda	d_node
			sta	irf.c_crc
			lda	d_node+1
			sta	irf.c_crc+1		;fixed this
			rts


;
s_node:			dc.w	l_dos_build

d_node:			dc.w	l_dos_build

inst_crc:		dc.w	0

block_w:		dc.w	0



wipe:
			mea	copy_buff,pr_ptr
			mea	copy_buff,fr0
			jsr	ifp
			jsr	fmove
			lda	_totbytes
			sta	fr0
			lda	_totbytes+1
			sta	fr0+1
			jsr	ifp
			jsr	fadd
			jsr	fpi
;
			lda	fr0
			sta	block_w
			lda	fr0+1
			sta	block_w+1
;
;~~~~~~~~~~~~~~~~~~debug
			JSR	PRINTSI
			dc.b	$9B," START $",-1
			LDA	# low COPY_BUFF
			LDX	# high COPY_BUFF
			JSR	H_CARD
			JSR	PRINTSI
			dc.b	" END $",-1
			LDA	BLOCK_W
			LDX	BLOCK_W+1
			JSR	H_CARD
;			RTS
			JSR	CR_LF
;
;			JSR	GET_KEY
;~~~~~~~~~~~~~~~~~~debug

;
			ldy	#$00
;
;       $FFFF
wp1:			lda	(pr_ptr),y
			jsr	crc_loop
			iny
			cpy	#$00
			bne	wp1
			inc	pr_ptr+1 ;WP1+2
			ldy	#$00
			lda	pr_ptr+1 ;WP1+2
			cmp	block_w+1
			bcc	wp1
			ldy	#$00
wp2:			lda	(pr_ptr),y
			jsr	crc_loop
			iny
			cpy	block_w
			bcc	wp2
			rts
;
next_run:

			lda	#$00
			cmp	INST_CRC
			bne	.ok
			cmp	INST_CRC+1

			bne	.ok
			JSR	printsi
			dc.b	$9B," Internal crc not set",-1
			rts


.ok:
;~~~~~~~~~~~~~~~~~~debug
			JSR	printsi
			dc.b	$9B,$9B,"          Crc = $",-1
			LDA	CRC_SUM
			LDX	CRC_SUM+1
			JSR	H_CARD
			JSR	printsi
			dc.b	$9B," Internal crc = $",-1
			LDA	INST_CRC
			LDX	INST_CRC+1
			JSR	H_CARD
			JSR	CR_LF
			JSR	CR_LF
;			RTS
;~~~~~~~~~~~~~~~~debug
			lda	crc_sum
			cmp	inst_crc
			bne	oh_Damn
			lda	crc_sum+1
			cmp	inst_crc+1
			bne	oh_Damn
			jsr	printsi
			dc.b	$9b,$9b," Command PASSED internal Crc Test",$9B,$9B,$FF
			rts
;
oh_Damn:
			jsr	printsi
			dc.b	$9b,$9b," Command "
			dc.b	<+128>,"Failed"
			dc.b	" internal Crc Test",$9B,$9B,-1
			rts
;

open_in:  		lda	#4
			jmp	do_open

open_out:		lda	#8
			jmp	do_open

open_app:		lda	#9
			jmp	do_open

open_updt:		lda	#12
			jmp	do_open

open_dir:		lda	#6
			jmp	do_open

open_raw:		lda	#20     	;open raw directory
			jmp	do_open

do_open:
			pha 		        ;open filespec pointed to by fn_ptr
			txa 		        ;
			pha
			jsr	close		;make sure device is closed
			pla
			tax
			pla
			sta	icaux1,x
			lda	#ccopen
			sta	iccom,x
			lda	fn_ptr
			sta	icbal,x
			lda	fn_ptr+1
			sta	icbah,x
			lda	#80
			sta	icbll,x
			lda	#0
			sta	icblh,x
			lda	#128		;for long directory (shouldn't hurt??)
			sta	icaux2,x
			jmp 	ciov


close:			lda	#ccclose
			sta	iccom,x
			jmp 	ciov

;
;
;  prints: prints string with address in PR_PTR, length byte in 0th byte
;  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

echos:
			ldy	#0
			lda	(pr_ptr),y		;get length to print
			beq	.xpri     		;exit, null string
			sta	.maxlth
			iny
			sty	.tempy

.pril:			ldy	.tempy
			lda	(pr_ptr),y
			cmp	#$00
			beq	.xpri
			jsr	echo
.prnext:		inc	.tempy
			dec	.maxlth
			bne	.pril
.xpri:			rts

.tempy:			dc.b	1
.maxlth:		dc.b    1

pr_mode:		dc.b	0




cr_lf:			lda	#$9b
			jsr	echo
			rts

;------------------------------
;   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





win_end:		ds.b	0
end_file:

	 		.org	$6000
copy_buff:
			dc.w	0		; this is always FFFF
			dc.w	0		; File orgs in memory
			dc.w	0		; length of file

BUFFER3:		dc.b	0,0,0		; $4c jmp location

irf.c_ver:		dc.b	0		; Current Version
irf.c_month:		dc.b	0		; First Compile Month
irf.c_day:		dc.b	0		; First Compile Day
irf.c_year_short:	dc.b	0		; single byte for year

buffer4:
irf.c_crc:		dc.w	0		; file CRC
;
;

;