;------------------------------------------------------------------------
;
;		Copyright 2010 Intergraded Logic Systems
;                  Source Code is Copyright Stephen J. Carden
;
;
;			Please do not share this source!
;------------------------------------------------------------------------
;      Strip the extra segmentation out of a com file
;------------------------------------------------------------------------
;              Strip.S
;  Written By Stephen J. Carden
;strip.com  
;
;STRIP.COM
;Atari 8-bit Ver 1.00 07-08-90
;Written By Stephen J. Carden
;
;
;	Split the org up because of the screen dli 6/1/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/27/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,"Strip.com   ",$9b
			.endm

;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; File revision history. Version Number in hex
;
file_ver:		equ   $15
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; 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 if it so I can print what I need
r..crl:			equ	$7d
r..crlf:		equ	$9b
r..space:		equ	$20
r..bypass:		equ	$15	;'B' for bypass dos check
r..supress:		equ	$ff

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


;
; CONSTANTS
;-----------
;
;   VARIABLES
;-----------
;
fnamel:   		equ  	$80    	;ds.b  1      		;FileNAME Length
findeof:  		equ  	$81	;ds.b  1      		;Check EOF flag
start:    		equ	$82	;ds.b  2      		;seg START addr
end:      		equ	$84	;ds.b  2      		;seg END addr
lsegend:  		equ	$86	;ds.b  2      		;Last SEG END
lendptr:  		equ	$88	;ds.b  2      		;Last END PnTR
period:   		equ	$8a	;ds.b  1      		;"." typed flag
locked:   		equ	$8b	;ds.b  1      		;file LOCKED flg
bytesr:   		equ	$8c	;ds.b  3      		;bcd BYTES Read
bytesw:  		equ	$8f	;ds.b  3      		;bcd BYTES Writn
extrab:   		equ	$92	;ds.b  2      		;bcd EXTRA bytes
extras:   		equ	$94	;ds.b  2      		;bcd EXTRA segts
myfiletemp:     	equ	$96	;ds.b  2      		;Work area
pnt:      		equ	$98	;ds.b  2      		;misc. PoiNTer
bpnt:     		equ	$9a	;ds.b  2      		;Buffer PoiNTer
tsave:    		equ	$9c	;ds.b  2      		;Text SAVE area
;

			.include	equates
			.include	globals
			.include	macros



			.org	$2600

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

do_it_now:
			jmp	main

			.org	$3000


;THIS IS THE DATA FILE FOR THE SCREEN
;-----------------------------
; This was done using printshop and then converted
; dc.b codeblocks  PSLABEL.bas exported it
;
;First 14 byte = logo
;next  26 bytes = text message
;
;
ps_data:

			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$03,$FF,$FF,$FF,$FF,$FF,$FF,$FF
			dc.b	$FF,$FF,$C0,$00,$00,$00,$00,$00
			dc.b	$3C,$18,$00,$18,$00,$00,$00,$00
			dc.b	$00,$00,$63,$00,$18,$18,$18,$00
			dc.b	$00,$00,$60,$00,$00,$00,$00,$00
			dc.b	$03,$FF,$FF,$FF,$FF,$FF,$FF,$FF
			dc.b	$FF,$FF,$C0,$00,$00,$00,$00,$00
			dc.b	$60,$7E,$7C,$00,$7C,$00,$3C,$3C
			dc.b	$66,$00,$63,$7C,$00,$7E,$7E,$3C
			dc.b	$7C,$00,$60,$66,$00,$00,$00,$00
			dc.b	$03,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$C0,$00,$00,$00,$00,$00
			dc.b	$3C,$18,$66,$38,$66,$00,$60,$66
			dc.b	$7F,$00,$6B,$66,$38,$18,$18,$66
			dc.b	$66,$00,$7C,$66,$00,$00,$00,$00
			dc.b	$3F,$3F,$FF,$FC,$FF,$F3,$FF,$FF
			dc.b	$FF,$FC,$FC,$00,$00,$00,$00,$00
			dc.b	$06,$18,$60,$18,$66,$00,$60,$66
			dc.b	$7F,$00,$7F,$60,$18,$18,$18,$7E
			dc.b	$66,$00,$66,$66,$00,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$F3,$FF,$FF
			dc.b	$FF,$FC,$CC,$00,$00,$00,$00,$00
			dc.b	$06,$18,$60,$18,$7C,$18,$60,$66
			dc.b	$6B,$00,$77,$60,$18,$18,$18,$60
			dc.b	$66,$00,$66,$3E,$00,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$F3,$FF,$FF
			dc.b	$FF,$FC,$CC,$00,$00,$00,$00,$00
			dc.b	$3C,$0E,$60,$3C,$60,$18,$3C,$3C
			dc.b	$63,$00,$63,$60,$3C,$0E,$0E,$3C
			dc.b	$66,$00,$7C,$0C,$00,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$F3,$FF,$FF
			dc.b	$FF,$FC,$CC,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$60,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$78,$00,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$F3,$FF,$FF
			dc.b	$FF,$FC,$CC,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$33,$00,$00,$00,$FF,$F3,$FE,$00
			dc.b	$00,$00,$CC,$00,$00,$00,$00,$00
			dc.b	$00,$00,$3C,$18,$00,$00,$60,$00
			dc.b	$00,$00,$06,$00,$00,$3C,$00,$00
			dc.b	$06,$00,$00,$00,$00,$00,$00,$00
			dc.b	$33,$FF,$FF,$FC,$FF,$F3,$FE,$FF
			dc.b	$FF,$FF,$CC,$00,$00,$00,$00,$00
			dc.b	$00,$00,$60,$7E,$3C,$7C,$60,$3C
			dc.b	$7C,$00,$06,$00,$00,$66,$3C,$7C
			dc.b	$06,$3C,$7C,$00,$00,$00,$00,$00
			dc.b	$33,$FF,$FF,$FC,$FF,$F3,$FE,$FF
			dc.b	$FF,$FF,$CC,$00,$00,$00,$00,$00
			dc.b	$00,$00,$3C,$18,$66,$66,$7C,$66
			dc.b	$66,$00,$06,$00,$00,$60,$06,$66
			dc.b	$3E,$66,$66,$00,$00,$00,$00,$00
			dc.b	$33,$FF,$FF,$FC,$FF,$F3,$FE,$FF
			dc.b	$FF,$FF,$CC,$00,$00,$00,$00,$00
			dc.b	$00,$00,$06,$18,$7E,$66,$66,$7E
			dc.b	$66,$00,$06,$00,$00,$60,$3E,$60
			dc.b	$66,$7E,$66,$00,$00,$00,$00,$00
			dc.b	$33,$FF,$FF,$FC,$FF,$F3,$FE,$FF
			dc.b	$FF,$FF,$CC,$00,$00,$00,$00,$00
			dc.b	$00,$00,$06,$18,$60,$7C,$66,$60
			dc.b	$66,$00,$66,$18,$00,$66,$66,$60
			dc.b	$66,$60,$66,$00,$00,$00,$00,$00
			dc.b	$33,$00,$00,$00,$FF,$F3,$FE,$FF
			dc.b	$FF,$FF,$CC,$00,$00,$00,$00,$00
			dc.b	$00,$00,$3C,$0E,$3C,$60,$66,$3C
			dc.b	$66,$00,$3C,$18,$00,$3C,$3E,$60
			dc.b	$3E,$3C,$66,$00,$00,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$F3,$FE,$FF
			dc.b	$FF,$FF,$CC,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$60,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$F3,$FE,$FF
			dc.b	$FF,$FF,$CC,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$F3,$FE,$FF
			dc.b	$FF,$FF,$CC,$00,$00,$00,$00,$00
			dc.b	$06,$00,$00,$00,$06,$00,$00,$3C
			dc.b	$60,$00,$38,$38,$00,$00,$00,$18
			dc.b	$60,$00,$00,$00,$18,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$F3,$FE,$FF
			dc.b	$FF,$FF,$CC,$00,$00,$00,$00,$3E
			dc.b	$00,$3C,$3C,$7C,$06,$3C,$7C,$66
			dc.b	$60,$3C,$18,$18,$3E,$3C,$66,$7E
			dc.b	$60,$00,$7C,$3C,$7E,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$F3,$FE,$FF
			dc.b	$FF,$FF,$CC,$00,$00,$00,$00,$60
			dc.b	$06,$60,$06,$66,$3E,$66,$66,$6E
			dc.b	$7C,$66,$18,$18,$60,$66,$66,$18
			dc.b	$7C,$00,$66,$66,$18,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$F3,$FE,$FF
			dc.b	$FF,$FF,$CC,$00,$00,$00,$00,$3C
			dc.b	$06,$60,$3E,$60,$66,$7E,$66,$6E
			dc.b	$66,$7E,$18,$18,$3C,$66,$66,$18
			dc.b	$66,$00,$66,$7E,$18,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$F3,$FE,$FF
			dc.b	$FF,$FF,$CC,$00,$00,$00,$00,$06
			dc.b	$06,$60,$66,$60,$66,$60,$66,$60
			dc.b	$66,$60,$18,$18,$06,$66,$66,$18
			dc.b	$66,$18,$66,$60,$18,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$F3,$FE,$FF
			dc.b	$FF,$FF,$CC,$00,$00,$00,$00,$7C
			dc.b	$06,$3C,$3E,$60,$3E,$3C,$66,$3E
			dc.b	$7C,$3C,$3C,$3C,$7C,$3C,$3E,$0E
			dc.b	$66,$18,$66,$3C,$0E,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$F3,$FE,$FF
			dc.b	$FF,$FF,$CC,$00,$00,$00,$00,$00
			dc.b	$3C,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$F3,$FE,$00
			dc.b	$00,$00,$CC,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$F3,$FF,$FF
			dc.b	$FF,$FC,$CC,$00,$00,$00,$00,$00
			dc.b	$7E,$00,$00,$18,$06,$00,$00,$18
			dc.b	$60,$00,$00,$3C,$00,$60,$18,$18
			dc.b	$00,$60,$60,$00,$00,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$F3,$FF,$FF
			dc.b	$FF,$FC,$CC,$00,$00,$00,$00,$00
			dc.b	$18,$7C,$3E,$00,$06,$3C,$00,$7E
			dc.b	$60,$3C,$00,$66,$00,$60,$00,$7E
			dc.b	$00,$60,$60,$3E,$00,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$F3,$FF,$FF
			dc.b	$FF,$FC,$CC,$00,$00,$00,$00,$00
			dc.b	$18,$66,$60,$38,$3E,$66,$00,$18
			dc.b	$7C,$66,$00,$3C,$7E,$7C,$38,$18
			dc.b	$00,$7C,$7C,$60,$00,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$F3,$FF,$FF
			dc.b	$FF,$FC,$CC,$00,$00,$00,$00,$00
			dc.b	$18,$66,$3C,$18,$66,$7E,$00,$18
			dc.b	$66,$7E,$00,$66,$00,$66,$18,$18
			dc.b	$00,$66,$66,$3C,$00,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$F3,$FF,$FF
			dc.b	$FF,$FC,$CC,$00,$00,$00,$00,$00
			dc.b	$18,$66,$06,$18,$66,$60,$00,$18
			dc.b	$66,$60,$00,$66,$00,$66,$18,$18
			dc.b	$00,$66,$66,$06,$00,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$F0,$00,$00
			dc.b	$3F,$FC,$CC,$00,$00,$00,$00,$00
			dc.b	$7E,$66,$7C,$3C,$3E,$3C,$00,$0E
			dc.b	$66,$3C,$00,$3C,$00,$7C,$3C,$0E
			dc.b	$00,$7C,$7C,$7C,$00,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$FF,$FF,$FF
			dc.b	$3F,$FC,$CC,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$FF,$FF,$FF
			dc.b	$3F,$FC,$CC,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$FF,$FF,$FF
			dc.b	$3F,$FC,$CC,$00,$00,$00,$00,$00
			dc.b	$7E,$00,$00,$00,$00,$00,$00,$7C
			dc.b	$00,$00,$00,$06,$00,$00,$06,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$FF,$FF,$FF
			dc.b	$3F,$FC,$CC,$00,$00,$00,$00,$00
			dc.b	$60,$66,$7C,$7C,$3C,$3E,$3E,$66
			dc.b	$7C,$3C,$00,$06,$66,$7C,$06,$7C
			dc.b	$3E,$00,$3C,$7C,$3E,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$FF,$FF,$FF
			dc.b	$3F,$FC,$CC,$00,$00,$00,$00,$00
			dc.b	$7C,$3C,$66,$66,$66,$60,$60,$66
			dc.b	$66,$66,$00,$3E,$66,$66,$3E,$66
			dc.b	$60,$00,$66,$66,$66,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$FF,$FF,$FF
			dc.b	$3F,$FC,$CC,$00,$00,$00,$00,$00
			dc.b	$60,$18,$66,$60,$7E,$3C,$3C,$7C
			dc.b	$60,$66,$00,$66,$66,$66,$66,$66
			dc.b	$3C,$00,$66,$60,$66,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$FF,$FF,$FF
			dc.b	$3F,$FC,$CC,$00,$00,$00,$00,$00
			dc.b	$60,$3C,$7C,$60,$60,$06,$06,$60
			dc.b	$60,$66,$18,$66,$3E,$66,$66,$66
			dc.b	$06,$18,$66,$60,$3E,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$FF,$FF,$FF
			dc.b	$3F,$FC,$CC,$00,$00,$00,$00,$00
			dc.b	$7E,$66,$60,$60,$3C,$7C,$7C,$60
			dc.b	$60,$3C,$18,$3E,$0C,$66,$3E,$66
			dc.b	$7C,$18,$3C,$60,$06,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$FF,$FF,$FF
			dc.b	$3F,$FC,$CC,$00,$00,$00,$00,$00
			dc.b	$00,$00,$60,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$78,$00,$00,$00
			dc.b	$00,$00,$00,$00,$7C,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$00,$00,$00,$00
			dc.b	$3F,$FC,$CC,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$FF,$FF,$FF
			dc.b	$FF,$FC,$CC,$00,$00,$00,$00,$00
			dc.b	$00,$00,$7C,$00,$00,$18,$00,$3C
			dc.b	$3C,$3C,$3C,$00,$00,$00,$00,$3C
			dc.b	$3C,$3C,$3C,$00,$00,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$FF,$FF,$FF
			dc.b	$FF,$FC,$CC,$00,$00,$00,$00,$00
			dc.b	$00,$00,$66,$3C,$7C,$7E,$00,$66
			dc.b	$66,$66,$66,$00,$3C,$7C,$00,$66
			dc.b	$66,$66,$66,$00,$00,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$FF,$FF,$FF
			dc.b	$FF,$FC,$CC,$00,$00,$00,$00,$00
			dc.b	$00,$00,$66,$66,$66,$18,$00,$3C
			dc.b	$3C,$3C,$3C,$00,$66,$66,$00,$3C
			dc.b	$3C,$3C,$3E,$00,$00,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$FF,$FF,$FF
			dc.b	$FF,$FC,$CC,$00,$00,$00,$00,$00
			dc.b	$00,$00,$7C,$66,$60,$18,$00,$66
			dc.b	$66,$66,$66,$00,$66,$60,$00,$66
			dc.b	$66,$66,$06,$00,$00,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$FF,$FF,$FF
			dc.b	$FF,$FC,$CC,$00,$00,$00,$00,$00
			dc.b	$00,$00,$60,$66,$60,$18,$00,$66
			dc.b	$66,$66,$66,$00,$66,$60,$00,$66
			dc.b	$66,$66,$0C,$00,$00,$00,$00,$00
			dc.b	$33,$3F,$FF,$FC,$FF,$FF,$FF,$FF
			dc.b	$FF,$FC,$CC,$00,$00,$00,$00,$00
			dc.b	$00,$00,$60,$3C,$60,$0E,$00,$3C
			dc.b	$3C,$3C,$3C,$00,$3C,$60,$00,$3C
			dc.b	$3C,$3C,$38,$00,$00,$00,$00,$00
			dc.b	$3F,$3F,$FF,$FC,$FF,$FF,$FF,$FF
			dc.b	$FF,$FC,$FC,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$03,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$C0,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$03,$FF,$FF,$FF,$FF,$FF,$FF,$FF
			dc.b	$FF,$FF,$C0,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$03,$FF,$FF,$FF,$FF,$FF,$FF,$FF
			dc.b	$FF,$FF,$C0,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$D1,$D2,$D2,$D2,$D2,$D2,$D2,$D2
			dc.b	$D2,$D2,$D2,$D2,$D2,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00
			dc.b	$00,$00,$00,$00,$00,$00,$00,$00


; RESERVED MEMORY
;-----------------
disp:  	;           DISPlay memory
			dc.b	<internal>,<+128>, ""
			dc.b	<internal>,<+128>, "|    Strip.Com is  (S)hareware 2012    |"
title:
			dc.b	<internal>,<+128>, ""
wlab1:
			dc.b	<internal>,<+128>, "|      REalDos is a product of ILS     |"
wlab2:			dc.b	<internal>,<+128>, ""
;
;status labels
			dc.b	<internal>,<+128>, "      | Bytes Read________"
bab2:			dc.b	<internal>,<+128>, "000000 |      "
			dc.b	<internal>,<+128>, "      | Bytes Written_____"
			dc.b	<internal>,<+128>, "000000 |      "
			dc.b	<internal>,<+128>, "      | Extra Bytes_______"
			dc.b	<internal>,<+128>, "__0000 |      "
			dc.b	<internal>,<+128>, "      | Extra Segments____"
			dc.b	<internal>,<+128>, "__0000 |      "
;
			dc.b	<internal>,<+128>, ""
			dc.b	<internal>,<+128>, "|    Paypal sjcardensr@bellsouth.net   |"
			dc.b	<internal>,<+128>, ""
dofile:
			dc.b	<internal>,<+128>, "|                                      |"
			dc.b	<internal>,<+128>, ""
			dc.b	<internal>,<+128>, "|"
disp352:		dc.b	<internal>,<+128>, "                                      |"
			dc.b	<internal>,<+128>, ""



; DLI COLORS
;--------------
dli_init:
			lda # low dli_1
			sta $0200
			lda # high dli_1
			sta $0201
			lda #$c0
			sta $d40e
			rts


dli_1:
			pha
			txa
			pha
			tya
			pha

correct_dli_1:
			lda	$d40b
			cmp	#111+1
			bcs	.d1
			cmp	#98+1
			bcs	.d4
			cmp	#42+1
			bcs	.d3
			cmp	#7+1
			bcs	.d2



.d1:			lda	#$80

			dc.b	$2c
.d2:			lda	#$40
			dc.b	$2c

.d3:			lda	#$80
			dc.b	$2c

.d4:			lda	#$40


			sta	$d018
			pla
			tya
			pla
			tax
			pla
			rti
;

;

;
;
steal:
			ldy #$00
steal1:			lda $00,y
			sta hold1,y
			lda $0200,y
			sta hold2,y
			iny
			cpy #$00
			bne steal1
			lda $022f
			sta hold3
			jsr dli_init
			rts
_restore:
			ldy #$00
restore1:
			lda hold1,y
			sta $00,y
			lda hold2,y
			sta $0200,y
			iny
			cpy #$00
			bne restore1
			lda hold3
			sta $022f
			rts
;
hold1:			ds.b	257
hold2:			ds.b	257
hold3:			dc.b	0
dl:
			dc.b	$f0,$70,$70,$4f
			dc.w	ps_data
			dc.b	$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f
			dc.b	$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f
			dc.b	$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f
			dc.b	$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f
			dc.b	$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f
			dc.b	$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f
			dc.b	$0f,$0f,$00,$80
			dc.b	$42
			dc.w	disp
			dc.b	2,2,2,2,2,2,2,2
			dc.b	2,2,2,2,2,$80,0,2,2,$82
			dc.b	$41
			dc.w	dl
;
;
; MAIN BODY
;-----------
screen_fname:		dc.b	0
fname:			ds.b	128

main:			lda	$14
			cmp	$14
			beq	main
			lda	$d301
			pha
			and	#$fe
			sta	$d301
			ldy	#$00
			jsr	$ffc6
			pla
			sta	$d301
			cld         		;Kill decimal!
			jsr	steal
			jsr	setup  		;Go set-up!
loop:			jsr	init   		;Get ready,
			jsr	linecrunch		;get name,
;
			jsr	show.f.name		; show the filename to screen
;

			jsr	read   		;read file,
			bmi	loop   		;and write it
			jsr	write  		;if no errors!
tammy:
			jsr	_restore
			jsr	close1
			jsr	close2
			rts
; ONE-SHOT SET-UP
;-----------------
setup:
			jsr	$e456  		;Initialize
			lda	#3     		;sound hardware
			sta	$d20f
			lda	#112   		;Disable break
			sta	$10    		;key...
			sta	$d20e
			ldx	#0     		;Reboot upon
			stx	$d201  		;Clear sound
			stx	$d208 		;channels
			ldx	#4     		;Init color
setclr:			lda	colors,x		;reg...
			sta	$02c4,x
			dex
			bpl	setclr
;
			lda	# low dl  		;Point to new
			sta	$0230  		;display list...
			lda	# high dl
			sta	$0230+1
;
;open keyboard for input on
;channel 2
;

			ldx	#$20   		;Channel 2
			lda	#3     		;Set command to
			sta	$0342,x		;"open"
			lda	# low keybd		;Point to
			sta	$0344,x		;keyboard
			lda	# high keybd		;filespec...
			sta	$0345,x
			lda	#4     		;Specify input
			sta	$034a,x
			lda	#0     		;AUX2 in unused
			sta	$034b,x
			jmp	$e456  		;Call cio!
;
;title & window labels
;
;initial colors
;
colors:			dc.b	$40,$ff,$90,$40,$00
;
linecrunch:
linec1:
			ldy	#63
lr1:			lda	($0a),y
			cmp	#$20
			beq	rr1
			cmp	#$9b
			beq	lre1
			iny
			cpy	#128
			bne	lr1
lre1:			jmp	no_line
rr1:
			iny
			ldx	#$00
read_1:			lda	($0a),y
			sta	fname,x


			stx	screen_fname

			cmp	#$9b
			beq	read_exit1
			cmp	#$20
			beq	read_exit
			inx
			iny
			cpy	#128
			bne	read_1
read_exit:
			iny
			lda ($0a),y
			cmp #'N'
			bne read_exit1
			lda #$01
			sta red
read_exit1:
			rts






red:			dc.b 0
;
;
;keyboard filespec
;
keybd:			dc.b	"K:",$9B
;
; SHOW 2 BCD DIGITS
;-------------------
;in: a - bcd byte
;    y - offset from start of
;        info window
bcd:
			pha        		;Save bcd
			sec        		;Convert 1st
			ror       		;digit to
			lsr       		;a character
			lsr
			lsr
			eor	#$80
			sta	bab2,y 		;and show it
			iny        		;Next position
			pla        		;Get bcd back
			and	#$0f   		;Keep lower ialf
			ora	#$10   		;Convert it and
			eor	#$80
			sta	bab2,y 		;show it!
			iny        		;Next space
			rts
;
; SHOW BYTES READ
;-----------------
shobr:
			ldx	#2     		;3 bytes total
			ldy	#0     		;Set position
sbr:			lda	bytesr,x		;Get bcd byte
			jsr	bcd    		;and show it!
			dex        		;Do next digit
			bpl	sbr
			rts
;
; SHOW BYTES WRITTEN
;--------------------
shobw:
			ldx	#2     		;3 bytes total
			ldy	#40    		;Set position
sbw:			lda	bytesw,x		;Get bcd byte
			jsr	bcd    		;and show it!
			dex        		;Get next digit
			bpl	sbw
			rts
;
; SHOW EXTRA BYTES
;------------------
shoeb:
			ldy	#82    		;Set cursor
			lda	extrab+1		;Get 1st byte
			jsr	bcd    		;and show it!
			lda	extrab 		;Get next one
			jmp	bcd    		;and show it!
;
; SHOW EXTRA SEGMENTS
;---------------------
shoes:			ldy	#122   		;Position cursor
			lda	extras+1		;Get 1st byte
			jsr	bcd    		;and show it
			lda	extras 		;Get 2nd byte
			jmp	bcd    		;and display!
;
;
; CLOSE IOCB #1
;---------------
close1:
			ldx	#$10   		;Set IOCB to 1
			lda	#$0c   		;"close" command
			sta	$0342,x
			jmp	$e456  		;CLose it up!
;
close2:
			ldx	#$20   		;Set IOCB to 1
			lda	#$0c   		;"close" command
			sta	$0342,x
			jmp	$e456  		;CLose it up!
;
; INITIALIZATION
;----------------
init:
			lda	# low buffer		;Point to
			sta	bpnt   		;start of buffer
			lda	# high buffer
			sta	bpnt+1
;
			lda	#0     		;Clear file
			sta	locked 		;locked flag
			ldx	#2
clrb:			sta	bytesr,x		;Clear read &
			sta	bytesw,x		;write counters
			dex
			bpl	clrb
;
			ldx	#1     		;Clear extra
clre:			sta	extrab,x		;counters...
			sta	extras,x
			dex
			bpl	clre
;
			jsr	shobr  		;Show all other
			jsr	shobw  		;status info...
			jsr	shoeb
			jmp	shoes
; PRINT MESSAGE
;---------------
;in: x - text lo byte
;    y - text hi byte
;
print:
			stx	pnt    		;Save text
			sty	pnt+1  		;address
			ldy	#0     		;Print text
dochar:			lda	(pnt),y		;until an
			cmp	#$9b   		;$9B is reached
			beq	padit
			sta	disp352,y
			iny
			bne	dochar
;
padit:   					;Now pad the
prexit:			rts
;
; ERROR SET-UP
;--------------
;in: x - error message lo byte
;    y - error message hi byte
;
errset:
			txa        		;Save lo byte...
			pha
			jsr	clrline		;Clear line
;
;Make a "ding" sound
;
			ldx	#$af   		;Initial volume
			lda	#20    		;Set channel 1
			sta	$d200  		;frequency
lower:			stx	$d201  		;and control
			lda	#0     		;Wait for a few
			sta	$14    		;jiffies...
delay:			lda	$14
			cmp	#2
			bcc	delay
			dex        		;and loop until
			cpx	#$a0   		;the volume is
			bcs	lower  		;zero
;
			pla        		;Get lo byte
			tax        		;back & print
			jsr	print  		;error message
			jsr	clrkbd
			jsr	_restore
			jsr	close1
			jsr	close2
			rts
;			jmp	($0a)
;
;GET A KEY
get_key:
			lda	#$00
			sta	$13
			lda	#$ff
			sta	$02fc
g_fff:
			lda	red
			cmp	#$00
			bne	g_ext
			lda	$13
			cmp	#$03
			bcs	g_ext
			lda	$02fc
			cmp	#$ff
			beq	g_fff
g_ext:			rts
;
;
; CLEAR KEYBOARD
;----------------
clrkbd:
			lda	#$ff
			sta	$02fc
			jsr	get_key
			rts
;
; SET FILENAME FOR CIO
;----------------------
;in: x - IOCB #
;
setfile:
			lda	# low fname
			sta	$0344,x
			lda	# high fname
			sta	$0345,x
			rts
;
; INC EXTRA BYTE COUNTER
;------------------------
;in: a - bcd number to add
;
addeb:
			sed        		;Decimal mode!
			clc        		;Add acc. to
			adc	extrab 		;extra byte
			sta	extrab 		;counter...
			lda	#0
			adc	extrab+1
			sta	extrab+1
			cld        		;Decimal off!
			jsr	shoeb  		;Print new value
			rts
;
; PUT BYTE IN BUFFER
;--------------------
;in:  a - byte to put in buffer
;out: y - $FF for error
;			0 for success
;
putbuf:
			ldx	$6a    		;Any space in
			cpx	bpnt+1 		;buffer?
			bne	notfull		;Yes, put byte
			ldx	# low bfmsg		;No, prepare
			ldy	# high bfmsg		;for an error
			jsr	errset
			ldy	#$ff   		;Return error
			rts        		;code and leave!
;
notfull:		ldy	#0     		;Put byte into
			sta	(bpnt),y		;ram buffer
			lda	bpnt   		;then add 1 to
			clc        		;the buffer
			adc	#1     		;pointer
			sta	bpnt
			lda	bpnt+1
			adc	#0
			sta	bpnt+1
			ldy	#0     		;Return success!
			rts        		;code and leave!
;
;buffer full error message
;
bfmsg:			dc.b	<internal>,<+128>, "     File too large. Press a key.     |"
			dc.b	$9b
;
; GENERIC IO ERROR HANDLER
;--------------------------
;in:  y - error number
;out: y - 0 to retry, else
;			error # (abort)
;
ioerror:
			tya        		;Save error # on
			pha        		;stack twice...
			pha
			ldx	#39    		;Save text that
savlin:			lda	disp352,x		;is on the
			sta	tsave,x		;interaction
			dex        		;line...
			bpl	savlin
;
			ldx	# low iomsg		;Prepare for
			ldy	# high iomsg		;error handling
			jsr	errset
			lda	#17    		;Print a '1' on
			sta	disp+363		;text line
			pla        		;Get # back
			sec        		;Subtract 100...
			sbc	#100
			ldx	#0     		;Divide result
div10:			cmp	#10    		;by 10 with the
			bcc	divided		;quotient in x
			sec        		;and remainder
			sbc	#10    		;in acc...
			inx
			bne	div10
divided:		ora	#16    		;Convert both to
			sta	disp+365		;internal code
			txa        		;and print...
			ora	#16
			sta	disp+364
;
rora:
			cmp	#'R'    		;(R)etry?
			bne	notr   		;Nope, not R
			pla        		;It's an R!
			ldx	#39    		;So, restore the
restore:		lda	tsave,x		;old text...
			sta	disp352,x
			dex
			bpl	restore
			ldy	#0     		;& return 0...
			rts
notr:			cmp	#'A'    		;(A)bort?
			bne	rora   		;Nope, wait
			pla        		;Yes, return
			tay        		;error code...
			rts
;
iomsg:			dc.b	<internal>,<+128>, "       I/O Error  Press any key       |"
			dc.b	$9b
;
; GET BYTE FROM CHANNEL 1
;-------------------------
;out: y - 0=success, or error #
;     a - byte read
;
;If FINDEOF is not zero and an
;EOF is found, error processing
;will be bypassed, but the error
;code will still be returned.
;
get1:
			ldx	#$10   		;IO channel 1
			lda	#7     		;Open command
			sta	$0342,x
			lda	#0     		;Get length to
			sta	$0348,x		;one character...
			sta	$0349,x
			jsr	$e456  		;Go get it!
			bmi	ohno   		;Check error!
			pha        		;Save char
			sed        		;Decimal on!
			lda	bytesr 		;Now add 1 to
			clc        		;to "bytes read"
			adc	#1     		;counter...
			sta	bytesr
			lda	bytesr+1
			adc	#0
			sta	bytesr+1		;Can u bonk?
			lda	bytesr+2
			adc	#0     		;
			sta	bytesr+2
			cld        		;Decimal off!
			jsr	shobr  		;Show new value!
			pla        		;Get char back &
			ldy	#0     		;reuturn success
			rts
;
ohno:			lda	findeof		;Error! Flag
			beq	sowhat 		;EOF? Nope.
			cpy	#136   		;Yes, is it an
			bne	sowhat 		;EOF? Nope.
			tya        		;Yes, return
			tay        		;error code!
			rts
sowhat:			jsr	ioerror		;Handle a
			beq	get1   		;standard error
			rts        		;and return.
;
; CLEAR INTERACTION LINE
;------------------------
clrline:
			ldx	#38    		;Clear 40 bytes
			lda	#$80   		; PUTTING BLANK SPACES IN
cll:			sta	disp352,x
			dex
			bpl	cll
			rts
;
; READ/COMPRESS FILE
;--------------------
;out: y - 0=success, $FF=ugh!
;
read:
			jsr	clrline		;Clear line
			jsr	close1 		;Close IOCB #1
			ldx	#$10   		;Open IOCB #1:
			lda	#3     		;open command...
			sta	$0342,x
			jsr	setfile		;Set filename
			lda	#4     		;Open for input
			sta	$034a,x		;only
			lda	#0     		;Clear 2nd aux
			sta	$034b,x		;byte as well as
			sta	lsegend		;a few vars...
			sta	lsegend+1
			sta	findeof
			jsr	$e456  		;Open it, nat!
			bpl	openok		;No errors!
;
			ldx	# low oemsg		;Uh-oh: error!
			ldy	# high oemsg		;Do error
			jsr	errset 		;stuff
nosir:
			cmp	#'R'    		;(R)etry?
			beq	read
			cmp	#'A'    		;(A)bort?
			bne	nosir 		;Nah!
			beq	reterr		;Yes, stop!
;
;make sure file is binary
;
openok:			jsr	get1   		;Get 1st byte
			bpl	noerr 		;No read errors!
err:			jsr	close1 		;Crud! an error!
reterr:			ldy	#$ff   		;Return error
			rts        		;flag
noerr:			sta	myfiletemp   		;Save 1st byte
			jsr	get1   		;Get 2nd byte
			bmi	err   		;Check error
			cmp	#$ff   		;Does byte=$FF?
			bne	notbin		;No! Not binary!
			lda	myfiletemp   		;Check 1st byte
			cmp	#$ff   		;is it $FF?
			beq	bin   		;Yes, Whew!
notbin:			ldx	# low nbmsg		;The file
			ldy	# high nbmsg		;is not binary
			jsr	errset 		;so abort and
			jmp	err   		;flag in Y.
bin:			jsr	putbuf 		;Well, the file
			bmi	err   		;is binary so
			lda	#$ff   		;put 2 $FF's in
			jsr	putbuf 		;the RAM buffer
			bmi	err
;
			ldx	# low rdmsg		;Print
			ldy	# high rdmsg		;"Reading..."
			jsr	print
;
;read the segment header
;information and determine
;if a "fake" binary header
;exists
;
getst:			inc	findeof		;EOF=ok
			jsr	get1   		;Get a byte
			bpl	ok    		;No errors!
			cpy	#136   		;EOF found?
			bne	err   		;No, an error!
			jsr	close1 		;Yes, the file
			ldy	#0     		;has been read
			rts        		;successfully!
ok:			dec	findeof		;EOF=bad
			sta	start  		;Save stat
			sta	myfiletemp   		;address lo byte
			jsr	get1   		;Get hi byte
			bmi	err   		;Check error
			sta	start+1		;Save byte...
			sta	myfiletemp+1
			cmp	#$ff   		;If the start
			bne	getend		;address=$FFFF
			lda	myfiletemp   		;then its not
			cmp	#$ff   		;the start addr-
			bne	getend		;ess and can be
			lda	#2     		;removed...
			jsr	addeb
			jmp	getst 		;Try again!
;
getend:			jsr	get1   		;Get end addr-
			bmi	err   		;ess lo byte
			sta	end    		;and save it
			jsr	get1   		;Now ge hi
			bmi	err   		;byte
			sta	end+1
;
;check if this seqment can be
;combined with the last one
;
			lda	myfiletemp   		;If this seq-
			sec        		;ment's start
			sbc	#1     		;address-1
			sta	myfiletemp   		;equals the last
			lda	myfiletemp+1 		;seqment's end-
			sbc	#0     		;ing address
			sta	myfiletemp+1 		;then the two
			cmp	lsegend+1		;seqments can
			bne	nocont		;be combined
			lda	myfiletemp   		;(they are
			cmp	lsegend		;continuous)
			bne	nocont
;
			ldy	#0     		;Combine 'em!
			lda	end    		;Merge the two
			sta	(lendptr),y		;segments by
			iny        		;making the 1st
			lda	end+1  		;have the 2nd's
			sta	(lendptr),y		;ending adr
			lda	#4     		;Record 4 extra
			jsr	addeb  		;bytes and
			sed        		;1 extra seq...
			lda	extras
			clc
			adc	#1
			sta	extras
			lda	extras+1
			adc	#0
			sta	extras+1
			cld
			jsr	shoes  		;Show new value
			jmp	newend		;Load seq data
;
nocont:			lda	start  		;Don't combine
			jsr	putbuf 		;so record the
			bpl	good  		;new seqment's
err2:			jmp	err   		;header data...
good:			lda	start+1
			jsr	putbuf
			bmi	err2
			lda	bpnt   		;(save the loc.
			sta	lendptr		;of the ending
			lda	bpnt+1 		;address...)
			sta	lendptr+1
			lda	end
			jsr	putbuf
			bmi	err2
			lda	end+1
			jsr	putbuf
			bmi	err2
newend:			lda	end    		;Record the new
			sta	lsegend		;ending address
			lda	end+1
			sta	lsegend+1
;
;read the actual segment data
;into RAM
;
load:			jsr	get1   		;Get a byte...
			bmi	err2
			jsr	putbuf 		;& save it
			bmi	err2
			lda	start+1		;All bytes read?
			cmp	end+1  		;If so, try to
			bcc	more  		;get another
			lda	start  		;segment!
			cmp	end
			bcc	more
			jmp	getst
more:			lda	start  		;Else, add 1 to
			clc        		;the byte count
			adc	#1     		;and keep on
			sta	start  		;readin'!
			lda	start+1
			adc	#0
			sta	start+1
			jmp	load
;
;misc. messages
;
oemsg:			dc.b	<internal>,<+128>, "   Can't open file.  Press any key    |"
			dc.b	$9b
nbmsg:			dc.b	<internal>,<+128>, "   Not a binary file.  Press a key.   |"
			dc.b	$9b
rdmsg:			dc.b	<internal>,<+128>, "           Reading File...            |"
			dc.b	$9b
;
;
; WRITE BUFFER TO DISK
;----------------------
write:
			lda	#0     		;Clear locked
			sta	locked 		;flag
			jsr	close1 		;Close IOCB #1
			lda	extrab 		;If no bytes
			bne	open  		;were removed
			lda	extrab+1		;then there is
			bne	open  		;no need to
			ldx	# low nnmsg		;rewrite the
			ldy	# high nnmsg		;file...
			jsr	errset
			rts
;
;open the file for input; if it
;is locked, unlock it
;
open:			jsr	clrline		;Clear text
			ldx	#$10   		;IOCB #1
			lda	#3     		;Open command...
			sta	$0342,x
			jsr	setfile		;Set filename
			lda	#8     		;Input mode...
			sta	$034a,x
			lda	#0
			sta	$034b,x
			jsr	$e456  		;Open file!
			bpl	_openok		;No errors!
			cpy	#167   		;File locked?
			beq	unlock		;Yes, unlock it!
			jsr	ioerror		;No, its just a
			beq	open  		;standard error
			rts
;
unlock:			inc	locked 		;Record this
retry:			ldx	#$10   		;Use IOCB #1
			lda	#36    		;Inlock command
			sta	$0342,x
			jsr	setfile		;Set filename
			lda	#0     		;Clear aux...
			sta	$034a,x
			sta	$034b,x
			jsr	$e456  		;Unlock file!
			bmi	.err   		;Handle error!
			jsr	close1 		;Close file &
			jmp	open  		;re-open!
.err:			jsr	ioerror		;Handle any
			beq	retry 		;IO errors
			rts
;
;now dump the buffer to disk,
;one byte at a time
;
_openok:		ldx	# low wrmsg		;Print
			ldy	# high wrmsg		;"Writing..."
			jsr	print  		;message
			lda	# low buffer		;Point to
			sta	start  		;start of RAM
			lda	# high buffer		;buffer...
			sta	start+1
;
dump:			ldx	#$10   		;Prepare to put
			lda	#11    		;a byte to disk
			sta	$0342,x		;using IOCB #1
			jsr	setfile		;Set filename
			lda	#0     		;Set length to 1
			sta	$0348,x
			sta	$0349,x
			ldy	#0     		;Get byte from
			lda	(start),y		;RAM buffer &
			jsr	$e456  		;write to disk!
			bpl	.noerr 		;No error!
			jsr	ioerror		;An error!
			beq	dump  		;R)etry
			jmp	close1 		;A)Abort
.noerr:			sed        		;Decimal on!
			lda	bytesw 		;Add 1 to the
			clc        		;"bytes written"
			adc	#1     		;counter...
			sta	bytesw
			lda	bytesw+1
			adc	#0
			sta	bytesw+1
			lda	bytesw+2
			adc	#0
			sta	bytesw+2
			cld        		;Decimal off!
			jsr	shobw  		;Show new value!
			lda	start  		;Move to next
			clc        		;byte in buffer
			adc	#1
			sta	start
			lda	start+1
			adc	#0
			sta	start+1
			cmp	bpnt+1 		;If not last
			bne	dump  		;byte then keep
			lda	start  		;on writin!
			cmp	bpnt
			bne	dump
;
;close file & lock if necessary
;
			jsr	close1 		;Close up file
			lda	locked 		;Re-lock it?
			beq	bye   		;Nah!
rel:			ldx	#$10   		;Prepare IOCB #1
			lda	#35    		;for re-locking
			sta	$0342,x		;procedure...
			jsr	setfile
			lda	#0
			sta	$034a,x
			sta	$034b,x
			jsr	$e456  		;Lock 'er up!
			bpl	bye   		;No errors!
			jsr	ioerror
			beq	rel   		;R)etry
			rts        		;A)bort
bye:			jsr	close1 		;Close IOCB #1
			ldx	# low dnmsg		;Print "Done"
			ldy	# high dnmsg		;message...
			jsr	print
;			jsr	clrkbd 		;Clear keyboard
			rts
;
;misc. messages
;
nnmsg:			dc.b	<internal>,<+128>, "   No need to rewrite. Press a Key.   |"
			dc.b	$9b
wrmsg:			dc.b	<internal>,<+128>, "            Writing file...           |"
			dc.b	$9b
dnmsg:			dc.b	<internal>,<+128>, "          Done. Press a key.          |"
			dc.b	$9b
;

;  writes: writes string with address in PR_PTR, length byte in 0th byte
;          Must enter with correct offset already in X!
;  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
show.f.name:
			lda	screen_fname
			cmp	#38
			bcc	.ok

			lda	#38
			sta	screen_fname	
.ok:			ldx	#$00
			mea	screen_fname,pr_ptr
 
writes:         	ldy	#0
			lda	(pr_ptr),y             		;get length to print
			beq	.xwri                  		;exit, null string
			sta	.maxlth
			inc	.maxlth
			iny
.pril:			lda	(pr_ptr),y
			jsr	xlate
			eor	#$80			;inverse it
			sta	dofile+1,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





;
;
;----------------------------
;   jsr  printsi             
;this prints an inline string
;     terminated by $ff      
;----------------------------
;        jsr   prints
;       .BYTE "print this",$9B,$FF
echosi:
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
			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


;
;
buffer:
;
;
no_line:
			jsr	_restore
			jsr	printsi
			dc.b	$9b,$9b,$9b
			dc.b	" Usage;",$9B
			dc.b	" Strip Dn:>path>filename.ext [Parm]",$9B
			dc.b	" Parm = 'N' no Delay on exit",$9B,$9B
			dc.b	" Press any key",$9B,$FF
			jsr	get_key
			jmp	$e474
;
win_end:		ds.b	0
;
; 