;------------------------------------------------------------------------
;		Copyright 2010 Integrated Logic Systems
;                  Source Code is Copyright Stephen J. Carden
;
;
;			Please do not share this source!
;------------------------------------------------------------------------
;                              Peek.com
;
;	This is a program to peak a byte and display it to the screen
;		init	2/24/2010	sjc new design
;		added hex delimeter 		2/25/2010	sjc		
;		added new code for registered user 2/26/2010	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,"Cr.com      ",$9b
			.endm

;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; File revision history. Version Number in hex
;
file_ver:		equ   $12
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; the Month in dec for the first time this revision 
;was compiled
;
c_month:		equ   8
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; the day in dec for the first time this revision 
;was compiled
c_day:			equ   28
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; the year in dec for the first time this revision 
;was compiled
c_year:			equ   2012
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Type of compiler used in program
;
; 0 = unknown Compiler
; 1 = xasm
; 2 = mac_65
; 3 = basic
; 4 = compiled basic xl
; 5 = C65
; 6 = Action
;
; We can add more as time goes on!
;
;
;
xasm:			equ	1
mac_65:			equ	2 
basic:			equ	3
basicxl:		equ	4
c65:			equ	5
action:			equ	6

file_compiler:		equ	xasm
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; is this relocatable code ?
; anyother value other than 1 or 2 would be unknown
r..yes:			equ	1
r..no:			equ	2
;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Gotta define if it can be relocated
l_relocatable:		equ	r..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..crl
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; The language the output file is in. 
;
;
; 0	=	Undifined
; 1	=	English
; 2	=	German
;
r..language:		equ	1
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;----------------------------
;
;     Zero Page Equates
;----------------------------
CD:		equ	$CD
i_stack:	equ	$CE
;

		.atascii

		.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

;
Start:
		TSX
		STX	i_stack
		LDA	LMARGN
		STA	L44BE
		LDA	#1
		STA	LMARGN
		jmp	title
L400C:

		jsr	end_of_header-3		; This call is in header.s this will display the intro message

title:
		JSR	printsi

		dc.b	$9b,$20
		dc.b	<+128>,""
		dc.b	$9b
		dc.b	" "
		dc.b     <+128>,"|ATASCII/ASCII Text File Converter|"
		dc.b	$9b
		dc.b     " "
		dc.b	<+128>,""
		dc.b	$9b,$9b,$9b
		dc.b	"         1) Atari to Ascii"
		dc.b	$9b,$9b
		dc.b	"         2) Ascii to Atari"
		dc.b	$9b,$9b,$9b
		dc.b	"           Your Choice? "
		dc.b	-1

l40b0:
		JSR	getkey_number
		cmp	#'2'+1
		BCS	L40B0

		JSR	L432E
		AND	#3
		TAX
		DEX
		STX	L44BC

		JSR	printsi
		dc.b	$9B,$9B,$9B
		dc.b	" Input Dn:>Path>filename.ext?",$9b
		dc.b	" ==> "
		dc.b	-1

		LDA	#low source_drv+3
		LDX	#high source_drv+3
		JSR	echos

		JSR	printsi
		dc.b	$9B,$9B
		dc.b	" Output Dn:>Path>filename.ext?",$9b
		dc.b	" ==> "
		dc.b	-1

		lda	#low dest_drv+3
		ldx	#high dest_drv+3
		JSR	echos
		LDX	#0
		STX	L44BD

		JSR	printsi
		dc.b	$9B,$9B
		dc.b	" Show file during conversion? "
		dc.b	-1


		JSR	get_key
		CMP	#'Y'
		BNE	L4133
		INC	L44BD


L4133:		JSR	L432E
		JSR	L432C
		LDA	#3
		LDX	#$10
		STA	ICCOM,X
		LDA	#low source_drv
		STA	ICBAL,X
		LDA	#high source_drv
		STA	ICBAH,X
		LDA	#4
		STA	ICAX1,X
		JSR	CIOV
		BPL	L4157
L4154:		JMP	L4242
;
L4157:		LDA	#3
		LDX	#$30
		STA	ICCOM,X
		LDA	#low dest_drv
		STA	ICBAL,X
		LDA	#high dest_drv
		STA	ICBAH,X
		LDA	#8
		STA	ICAX1,X
		JSR	CIOV
		BMI	L4154
		LDA	#$7D
		JSR	L432E
		LDA	L44BD
		BNE	L4195

		JSR	printsi
		dc.b	$9B,$9B,$7F
		dc.b	"Converting File..."
		dc.b	-1

L4195:		LDA	L44BC
		BNE	L41AF
L419A:		JSR	L41F2
		CMP	#$9B			; atari cr
		BNE	L41A8
		LDA	#$0D
		JSR	L41CC
		LDA	#$0A
L41A8:		AND	#$7F
		JSR	L41CC
		BPL	L419A
L41AF:		JSR	L41F2
		CMP	#$0D
		BNE	L41C6
L41B6:		LDA	#$9B
		JSR	L41CC
		JSR	L41F2
		CMP	#$0D
		BEQ	L41B6
		CMP	#$0A
		BEQ	L41AF
L41C6:		JSR	L41CC
		JMP	L41AF
;
L41CC:		TAY
		LDX	#$30
		LDA	#$0B
		STA	ICCOM,X
		LDA	#0
		STA	ICBLL,X
		STA	ICBLH,X
		TYA
		PHA
		JSR	CIOV
		BPL	L41E6
L41E3:		JMP	L4242
;
L41E6:		PLA
		TAX
		LDA	L44BD
		BEQ	L41F1
		TXA
		JMP	L432E
;
L41F1:		RTS
;
L41F2:		LDA	#7
		LDX	#$10
		STA	ICCOM,X
		LDA	#0
		STA	ICBLL,X
		STA	ICBLH,X
		JSR	CIOV
		BMI	L4207
		RTS
;
L4207:		CPY	#$88
		BNE	L41E3
		JSR	close1

		JSR	printsi
		dc.b	$9B,$9B
		dc.b	"  Done... Press any key: "
		dc.b	-1

		jsr	get_key
		JMP	L400C
;
exit:		JSR	close1
		JSR	close2
		LDX	i_stack
		TXS
		LDA	L44BE
		STA	LMARGN
		RTS
;
L4242:		TYA
		JSR	error_hex
		LDA	#low l4499
		LDX	#high l4499
		LDY	#35
		JSR	get_string
		JSR	get_key
		JSR	close1
		JSR	close2
		LDX	i_stack
		TXS
		JMP	L400C
;
L425E:		dc.b	40

echos:		STA	L42A1+1
		STX	L42A1+2
		LDY	#40-1
L4267:		LDA	#' '
		JSR	L42A1
		DEY
		BPL	L4267
		JSR	ding
		LDY	#0
L4274:		STY	CD
		JSR	get_key2
		LDY	CD
		CMP	#$7E		;	"'"
		BEQ	L4291
		CMP	#$9B
		BEQ	L42A5
		CPY	L425E
		BEQ	L4274
		JSR	L432E
		JSR	L42A1
		INY
		BNE	L4274
L4291:		CPY	#0
		BEQ	L4274
		JSR	L432E
		DEY
		LDA	#' '
		JSR	L42A1
		JMP	L4274
;
L42A1:		STA	$FFFF,Y
		RTS
;
;
;
;
L42A5:		JSR	L42A1
		LDA	L42A1+1
		STA	L42C7+1
		STA	L42D4+1
		SEC
		SBC	#3
		STA	L42D7+1
		LDA	L42A1+2
		STA	L42C7+2
		STA	L42D4+2
		SBC	#0
		STA	L42D7+2
		LDX	#2
L42C7:		LDA	$FFFF,X
		CMP	#'9'+1
		BEQ	L42D2
		DEX
		BPL	L42C7
		RTS
;
L42D2:		LDX	#0
L42D4:		LDA	$FFFF,X
l42d7:		STA	$FFFF,X
		CMP	#$9B
		BEQ	L42E1
		INX
		BNE	L42D4
L42E1:		RTS
;
get_key:	JSR	ding
get_key2:	JSR	close2
		LDA	#3
		STA	ICCOM,X
		LDA	#low kdev
		STA	ICBAL,X
		LDA	#high kdev
		STA	ICBAH,X
		LDA	#4
		STA	ICAX1,X
		JSR	CIOV
		BPL	L4304
		JMP	L4242
;
L4304:		LDX	#$20
		LDA	#7
		STA	ICCOM,X
		LDA	#0
		STA	ICBLL,X
		STA	ICBLH,X
		JSR	CIOV
		BMI	L4345
		CMP	#$1B
		BNE	L431F
		JMP	exit
;
L431F:		RTS
;
getkey_number:
		JSR	get_key
		CMP	#'1'
		BCC	getkey_number
		CMP	#'9'
		BCS	getkey_number
		RTS
;
L432C:		LDA	#$9B
L432E:		PHA
		TAX
		TYA
		PHA
		LDA	#$0B
		STA	ICCOM
		TXA
		LDX	#0
		STX	ICBLL
		STX	ICBLH
		JSR	CIOV
		BPL	L4348
L4345:		JMP	L4242
;
L4348:		PLA
		TAY
		PLA
		RTS
;
printsi:
		PLA
		STA	$cb
		CLC
		ADC	#1
		STA	ICBAL
		PLA
		STA	$cb+1
		ADC	#0
		STA	ICBAH
		LDX	#0
		STX	ICBLL
		STX	ICBLH
		LDY	#0
.a:		LDA	($CB),Y
		CMP	#$FF
		BEQ	.d
		INC	$cb
		BNE	.b
		INC	$cb+1
.b:		INC	ICBLL
		BNE	.c
		INC	ICBLH
.c:		JMP	.a
;
.d:		LDA	$cb+1
		PHA
		LDA	$cb
		PHA
		LDA	#$0B
		STA	ICCOM,X
		JSR	CIOV
		BMI	L43A8
		RTS
;
;
;
;
;
get_string:
		STA	ICBAL
		STX	ICBAH
		STY	ICBLL
		LDX	#0
		STX	ICBLH
		LDA	#$0B
		STA	ICCOM
		JSR	CIOV
		BMI	L43A8
		RTS
;
L43A8:		JMP	L4242
;
close1:		LDA	#$0C
		LDX	#$10
		STA	ICCOM,X
		JSR	CIOV
		BMI	L43A8

close3:
		LDX	#$30
		LDA	#$0C
		STA	ICCOM,X
		JSR	CIOV
		BMI	L43A8
		RTS
;
close2:		LDX	#$20
		LDA	#$0C
		STA	ICCOM,X
		JSR	CIOV
		BMI	L43A8
		RTS
;
error_hex:	PHA
		PHA
		JSR	error_dec
		PLA
		LDX	#0
		LSR
		LSR
		LSR
		LSR
		JSR	L43E1
		PLA
L43E1:		AND	#$0F
		ORA	#$30
		CMP	#$3A
		BCC	L43EB
		ADC	#6
L43EB:		ORA	#$80
		STA	L44A9,X
		INX
		RTS
;
error_dec:	LDX	#0
		LDY	#0
L43F6:		CMP	#100
		BCC	L43FF
		SBC	#100
		INY
		BNE	L43F6
L43FF:		JSR	L440F
L4402:		CMP	#$0A
		BCC	L440B
		SBC	#$0A
		INY
		BNE	L4402
L440B:		JSR	L440F
		TAY
L440F:		PHA
		TYA
		ORA	#$B0
		STA	L44A3,X
		LDY	#0
		INX
		PLA
		RTS
;
ding:		LDA	#$12
		STA	AUDF1
		LDA	#$AF
		STA	AUDC1
		LDY	#$19
		JSR	.a
.b:		STA	AUDC1
		LDY	#8
		JSR	.a
		SBC	#1
		CMP	#$9F
		BNE	.b
		RTS
;
.a:		DEX
		BNE	.a
		DEY
		BNE	.a
		RTS
;



kdev:		dc.b	"K:",$9b


source_drv:	dc.b	"D1:",$9b
		ds.b	39

dest_drv:	dc.b	"D1:"

		ds.b	40

;
;
l4499:
		dc.b	$9B,$9B
		dc.b	<+128>,"  Error "
l44a3:		dc.b	<+128>,"000  ("
l44a9:		dc.b    <+128>,"ff)"
		dc.b	<+128>," Press any Key  "

;
L44BC:		dc.b	0  ;
L44BD:		dc.b	0  ;
L44BE:		dc.b	0  ;
;
win_end:	ds.b	0
;
;----------------------------
;
