;------------------------------------------------------------------------
;
;		Copyright 2012 Intergraded Logic Systems
;			   Source Code is Copyright Stephen J. Carden
;
;
;			Please do not share this source!
;------------------------------------------------------------------------
;				Xtype.com
;			This program is to replace
;			 command line Type command
;
;Added stuff for walter.
; found a bug and fixed it.. if the first parm is not legal it drive the program nuts
;
;added tab conversion for 127==>$09   $09==>127
;
;
;	  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;------------------------------------------------------------------------
; Notes: o This source code MAY NOT be placed for download on any BBS's!
;	   o "mea" is a macro that loads the address of the first field
;		into the pointer specified by the second field.
;------------------------------------------------------------------------
; Assembler:  MADMAC (tm) ST Cross Assembler (Atari Corp)
;		   XASM   st and IBM VERSIONS
;------------------------------------------------------------------------
com_file_name:		.macro
;			dc.b   12,"filename.ext",$9b
			dc.b   12,"Xtype.com   ",$9b
			.endm

;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; File revision history. Version Number in hex
;
file_ver:		equ   $19
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; 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   19
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; 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
r..supress:		equ	$ff


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


			.include	equates
			.include	globals
			.include	macros

			.org  $4000

win_start:
header_info:
			.include	header				; this reads info out of the header and displays to screen
;									; based on info stored at the front of the file
start:
			ldx	#disk1
			jsr	close
			ldx	#disk2
			jsr	close

			lda	comtab
			CLC 
			adc	# low ZCRNAME
			sta	cli.crunch+1
			lda	comtab+1
			adc	# high ZCRNAME
			sta	cli.crunch+2
			jsr	cli.crunch
			bne	.get_parm1				; nothing there
			jmp	parm_errors

.get_parm1:
			lda	comtab
			CLC 
			adc	# low COMFNAM
			sta	s_ptr
			lda	comtab+1
			adc	# high COMFNAM
			sta	s_ptr+1
			mea	parm_1,d_ptr
			jsr	tostr


			jsr	cli.crunch
			bne	.get_parm2
			jmp	.exit

.get_parm2:		lda	comtab
			CLC 
			adc	# low COMFNAM
			sta	s_ptr
			lda	comtab+1
			adc	# high COMFNAM
			sta	s_ptr+1
			mea	parm_2,d_ptr
			jsr	tostr

			ldy	#$04
			cpy	parm_2
			bcs	.exit
			lda	parm_2,y
			cmp	#'/'
			bne	.exit
.p2:			iny
			lda	parm_2,y
			jsr	upcase
			cmp	#'N'
			bne	.pa
			inc	need_pause
.pa:			cmp	#'A'
			bne	.pb
			inc	do_type
.pb:			cmp	#'R'
			bne	.pc
			inc	strip
.pc:			cmp	#'S'
			bne	.p.done
			inc	speed
.p.done:
			cpy	parm_2
			bcc	.p2


.exit:

			mea	parm_1,s_ptr
			mea	filename,d_ptr
			jsr	toascii


			lda	consol
			cmp	#consol_any
			beq	.no_tell
		
			jsr	printsi		
			dc.b	$9b," CLI Parms"
			dc.b	$9b,"Parm_1 =",-1
			mea	parm_1,pr_ptr
			jsr	echos

			jsr	printsi
			dc.b	$9b,"Parm_2 =",-1
			mea	parm_2,pr_ptr
			jsr	echos


			rts

.no_tell:		lda	parm_1+2		;0,"dn:>
			cmp	#'1'
			bmi	show_help
			cmp	#'9'+1
			bcs	show_help
			lda	parm_1+3
			cmp	#':'
			bne	show_help
			lda	Parm_1+4
			cmp	#'/'
			beq	show_help

			jmp	type

cli.crunch:		jmp	$0000

parm_errors:
			jsr	start-3
Show_help:		jsr	printsi
			dc.b	$9B,$9B
			dc.b	" "
			dc.b	<+128>,"Syntax"
			dc.b	" for use:",$9b
			dc.b	" Xtype "
			dc.b	<+128>,"[Dn:>dir>]"
			dc.b	"fname.ext [parm]",$9b
			dc.b	" Drive and path ",$9b,$9b
			dc.b	" Parm = /N Non-stop Read",$9b
			dc.b	" Parm = /R Remove Inverse",$9b
			dc.b	" Parm = /A Ascii to Atascii",$9b
			dc.b	" Parm = /S Slow screen display",$9b
			dc.b	" Parm = /NRAS in any order ok!",$9b
			dc.b	$9b,$9b
			dc.b	" These Functions are "
			dc.b	<+128>,"Hot Keyed"
			dc.b	$9b
			dc.b	" And can be called while a file"
			dc.b	$9b
			dc.b	" being Xtyped!"
			dc.b	$9b
			dc.b	" "
			dc.b	<+128>,"[Select]"
			dc.b	"= toggles "
			dc.b	<+128>,"[-More-]"
			dc.b	$9b
			dc.b	" "
			dc.b	<+128>,"[Start]"
			dc.b	" = toggles Inverse strip",$9b
			dc.b	" "
			dc.b	<+128>,"[Option]"
			dc.b	"= toggles Screen Speed",$9b
			dc.b	" "
			dc.b	<+128>,"[Brk]"
			dc.b	" Aborts File",$9b
			dc.b	" "
			dc.b	<+128>,"[Control+N]"
			dc.b	" Quits File operation",$9b
			dc.b	$9b

			dc.b	$9b,-1
			RTS

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Vars
need_pause:		dc.b	0
strip:			dc.b	0
do_type:		dc.b	0
speed:			dc.b	0
FILENAME:		ds.b	80

parm_1:			ds.b	80
parm_2:			ds.b	80
parm_3:			ds.b	80
in_str:			ds.b	128
instr:			ds.b	128
;


;		View a text file to the screen
;		~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
type:
	 		lda	do_type
			sta	.xlate


			mea	FILENAME,fn_ptr
			ldx	#disk_2
			jsr	open_in
			bpl	.clearscr
			jmp	system_error		;damn!

.clearscr:		lda	#125
			jsr	putlocal
			jsr	start-3			; display our header

.read_loop:		ldx	#disk_2
			lda	#ccgetch
			sta	iccom,x
			lda	#0			;get it in A reg
			sta	icbal,x
			sta	icbah,x
			sta	icbll,x
			sta	icblh,x
			jsr	ciov			;get line from directory
			bpl	.readOK
.readerr:		tya
			pha
			ldx	#disk_2 		;close out the device
			jsr	close
			pla
			tay
			cpy	#136			;was it an EOF?
			beq	.exit			;yes, it's OK..
			jmp	system_error

.readOK:
			ldx	.xlate			;translating ascii?
			beq	.noxlate
			cmp	#'~'
			bne	.bks
			lda	#'-'

.bks:			cmp	#127			; Atari Tab Key
			bne	.tab
			lda	#$09
			bne	.ascii

.tab:			cmp	#$09			;ascii Tab
			bne	.ascii
			lda	#127			;atari Tab
.ascii:
			cmp	#10			;linefeed?
			beq	.skip_it		;yes, ignore it
			cmp	#13
			bne	.noxlate
			lda	#$9b
			jmp	.nostrip
.noxlate:
			cmp	#$9b
			beq	.nostrip
			ldx	Strip
			beq	.nostrip
			and	#$7f
.nostrip:
			ldx	speed
			beq	.fast
			jsr	putlocal		; Slow Screen output
			jmp	.skip_it

.fast:			jsr	fast_output		;Fast display the character

.skip_it:
			jsr	check_break
			lda	need_pause
			cmp	#$00
			bne	.notatbot

			lda	row
			cmp	#23			;at bottom of screen?
			bcc	.notatbot

			lda	#$00
			sta	need_pause
			jsr	more	

			lda	#125
			jsr	putlocal
.notatbot:		jmp	.read_loop
.aborted:		ldy	#136			;fake EOF on abort
			bne	.readerr
.exit:			rts

.xlate: 		dc.b	0
.temp.a			dc.b	0

;
more:
			lda	#$ff
			sta	764
			jsr 	printsi
			dc.b 	<+128>,"[ - MORE - ]"
			dc.b 	-1
			jsr 	get_key
			cmp 	#$7e    		; back space key out of here
			beq 	.esc_more
			cmp	#$1b			;esc key
			beq	.esc_more
;			cmp	#$1c			;up arrow
;			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
			rts

.esc_more:
			lda	#$00
			sta	752
			ldx	#disk_2 		;close out the device
			jsr	close
			jsr	printsi
			dc.b	$9b,$9b,-1
			pla
			pla
			rts



check_break:
			lda	consol
			cmp	#0			; Control+Start+Select
			beq	.quit			; close it up and quit!
			cmp	#5			; Select Consol Key
			beq	..Select		; not assigned yet
			cmp	#6			; Start Consol Key
			beq	..Start			; not assigned yet
			cmp	#3			; Option Consol Key
			beq	..Option		; not assigned yet


			lda	764			; Check the raw key 
			cmp	$ff
			beq	.do_brk
			cmp	#$1c			; esc key
			beq	.quit
			cmp	#$a3			; Control N
			beq	.quit			; gonna close it up now and exit
			cmp	#$21			; Space bar 
			beq	.do_more		; No you get the More menu
			cmp	#$66			; "?" help screen
			bne	.do_brk
			jmp	.help			; Lets show a help screen


.do_brk:		lda	brkkey
			cmp	#$00
			bne	.exit
			lda	#$80
			sta	brkkey
			lda	#$00
			sta	752
			jsr	printsi
			dc.b	$9b
			dc.b	<+128>,"Break"
			dc.b	" Aborted!",$9b
			dc.b	$9b,-1

.quit:			ldx	#disk_2 		;close out the device
			jsr	close
			lda	#$ff
			sta	ch
			jsr	printsi
			dc.b	$9b
			dc.b	" Xtype Operation Ended!",$9b
			dc.b	$9b,-1
			pla
			pla
.exit:			rts

..Select:		jmp	toggle_More
..Start:		jmp	toggle_strip
..Option:		jmp	toggle_speed
.do_more:		jmp	more

.help:			jsr	printsi
			dc.b	$9b,$9b
			dc.b	" =====================================",$9b,-1
			jsr	Show_help
			jsr	more
			rts




toggle_More:
.hold:			lda	consol
			cmp	#$07			; No Consol key Pressed
			bne	.hold			; wait untill you release consol key
			lda	need_pause
			cmp	#$00
			beq	.a
			lda	#$00
			dc.b	$2c			; tell the stack to skip 2 bytes
.a:			lda	#$01
			sta	need_pause
			rts

toggle_strip:
.hold:			lda	consol
			cmp	#$07			; No Consol key Pressed
			bne	.hold			; wait untill you release consol key
			lda	strip
			cmp	#$00
			beq	.a
			lda	#$00
			dc.b	$2c			; tell the stack to skip 2 bytes
.a:			lda	#$01
			sta	strip
			rts

toggle_speed:
.hold:			lda	consol
			cmp	#$07			; No Consol key Pressed
			bne	.hold			; No Consol key Pressed
			lda	speed
			cmp	#$00
			beq	.a
			lda	#$00
			dc.b	$2c			; tell the stack to skip 2 bytes
.a:			lda	#$01
			sta	speed
			rts


;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;   GET KEY  ROUTEEN           
;this routeen get's one key and
;return it to the accumlator   
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;
get_key:		stx	$b6
			sty	$b7
			jsr	.a
			ldx	$b6
			ldy	$b7
			rts
.a:			lda	$e420+5
			pha
			lda	$e420+4
			pha
			rts


;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; This is my ciov open file Calls
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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


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

system_error:		sty	.hold
			ldx	#$20
			jsr	close
			inc	need_pause		;pause on any error
			jsr	printsi
			dc.b	$9b,$9b
			dc.b	"System Error: ",-1
			lda	.hold
			jsr	pr_byte
			jsr	printsi
			dc.b	$9b,-1
			rts


.hold:			dc.b	0


;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Genric Close command
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
close:
			lda	#$0c
			sta	$0342,x
			jsr	ciov
			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
;
echo:
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
;



;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;Prints a byte or a card to the screen
pr_byte:
			ldx	#$00
pr_card:
			sta	fr0
			stx	fr0+1
			lda	#$00
			sta	cix
			sta	.bytecard
			jsr	ifp
			jsr	fasc
			ldy	#$00
.aprbloop:
			inc	.bytecard
			lda	($f3),y
			php
			and	#$7f
			sta	.bytecard+1,y
			iny
			plp
			bpl	.aprbloop
			mea	.bytecard,pr_ptr
			jsr	echos
			rts

.bytecard:		ds.b	10



cr_lf:
			jsr	printsi
			dc.b	$9b,-1
			rts



;  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


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



;	Make a length-byte string from an ASCII ($9b terminated) string
;	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

tostr:			ldy	#0
.tfe:			lda	(s_ptr),y			;find end of string
			beq	.gotend
			cmp	#$9b
			beq	.gotend
			iny
			bne	.tfe
.gotend:		sty	.lth				;save length
			cpy	#0
			beq	.rtn
			ldy	#0
.loop:			lda	(s_ptr),y
			iny
			sta	(d_ptr),y
			cpy	.lth
			bcc	.loop
.rtn:			ldy	#0
			lda	.lth
			sta	(d_ptr),y
			rts

.lth:			dc.b    1

;
;	  Move string pointed to by s_ptr to string pointed to by d_ptr
;	  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


move_str:		ldy	#0
			lda	(s_ptr),y 			;get lth byte
			tay					;go backwards
.loop:			lda	(s_ptr),y
			sta	(d_ptr),y
			cpy	#0
			beq	.done
			dey
			jmp	.loop
.done:			rts



;	  Return the length of string at s_ptr in accumulator
;	  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

length:			ldy	#0
			lda	(s_ptr),y
			rts


;	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





win_end:		ds.b	0
;
buffer:			ds.b	0
;
;