TestMode	=	0

	INCDIR	"INCLUDE:"
	INCLUDE	"Darkness.I"
	INCLUDE	"LibOffSet"
	INCLUDE	"Exec/Memory.I"
	INCLUDE	"Dos/Dos.I"

* 4-Jun-93
* 47 days of hard coding

; V1.01
; - Added bigger understanding of PC box characters.
; - Now also understands one-wide box chars, and thick corner changed to #,
;   single corner to +.

; V1.02
; - Added bad mode error, and error on no space between mode and the rest.

; V1.10
; - Cut endspace.
; - Text output.

; V1.13
; - Percentage & size change.
; - Extra LF.
; - Extra CR removal in ToPC mode.

; V1.16
; - Faster translate routines - 25% speedup in FromPC.
; - 6 more in FromPC.
; - New helptext.

; V1.18  11-Feb-93
; - Upper and lower case modes.

; V1.22  19-Feb-93
; - Tabs to spaces:
; - 3 new PC box chars.
; - Bug fixed that confused Port if the end of the commandline had spaces.
; - Spaces to tabs.

; V1.24  21-Feb-93
; - Size reduced by 48.
; - Bug fixed where tabconversion wasn't turned on in SpacesToTabs
;   causing some strange behavior.
; - Reduced code size by making routines use same parts of code.
; - Logic check for options.
; - +20% when quiet.

; V1.25  11-Mar-93
; - Buffer overflow bug fixed.
; - New table conversion system.
; - Buffered input.
; - Handles one filename differently.
; - CTRL+C detection.
; - Doesn't screw up PP files.
; - 6856 -> 6636.
; - 9 new PC chars.
; - End LF removal.
; - No longer translates one space.

; V1.28  20-Mar-93
; - First 7292 -> 6952 = -340 !
; - Bug fixed: Some bytes got cut off from the beginning if the file was
;   less than 4 bytes long.
; - Bug fix: Amy->PC didn't make CR+LF pairs as it should have in V1.25
;   same with Amy->SF
; - Most modes use table now.
; - Priorities changed for EndSpace removal and translation. This also fixes
;   the bug where endLFs didn't get removed if there were nulls or CTRL+Zs
;   etc.
; - Code rationalized, size down.
; - Doesn't trigger anything from CR's.
; - Make EOLs option.
; - Automode.

; V1.30  27-Mar-93
; - Added 13 PC chars.
; - No longer can convert 1 space to tabs (made no sense).

; V1.37  30-Apr-93
; - Changed automatic "Mode" to "Type".
; - Full PC->Amiga support implemented.
; - Optimized and reduced code.
; - Now uses includes.
; - Automatically find differently suffixed files by the the prefacing
;   name.
; - Ami changed to Amy.
; - A mode which throws out everything except pure ASCII stuff.
; - Fixed the slight flickering of various texts.
; - Fixed a bug which caused endspace removal to leave a space after some
;   lines when SpacesToTabs was on.
; - A fast PC->Amiga conversion routine.
; - Now you can specify only the destination directory, and the file will
;   be written correctly.

; V1.38  5-May-93
; - Fixed some small bugs in commandline handling which caused big shit.
;   65535 bytes big, ;)
; - Fixed errors in stack handling which caused gurus on errors.

; V1.39  4-Jun-93
; - Fixed the FromPC table, most of the box characters were messed up, and
;   made a few better choices for conversion.
; - FromPC didn't remove CRs anymore, oops.
; - ToPC and ToSF7 didn't work, now they do. (Were always FromPC)

; Things to do:
; - Load the first 10K, check, then load the rest.
; - Don't scan back in the file when checking for PP.
; - Adjustment of the buffer sizes used for conversion.
; - Wildcards.
; - Some kind of a config file.
; - Full Amiga->PC character support.
; - Disable break when converting to same file.
; - Add exit error codes.
; - PowerPacker decrunch.

; During the program:
; A0 = Source
; A1 = Dest
; A2 = Spacebuf
; A3 = Translation table

; D0 = Current char
; D1 = Load counter
; D2 = Savebyte counter
; D3 = translation char


	IF	TestMode=1
	lea	Test_ComLine,a0
	move.l	#Test_Len,d0
	ENDC

ProgStart:
	move.l	a7,OldStack
	clr.b	-1(a0,d0.l)
	movem.l	a0,-(a7)
	move.w	d0,CommandLen
	add.l	d0,a0
	subq.l	#1,a0
	move.l	a0,CommandEnd

	lea	_DosName,a1
	moveq	#0,d0
	move.l	ExecBase,a6
	jsr	_LVOOpenLibrary(a6)
	move.l	d0,_DosBase

	move.l	_DosBase,a6
	jsr	_LVOOutput(a6)
	move.l	d0,OutStruct

	IF	TestMode=1
	bne	Err_TestMode
	ENDC

	move.l	#Text_CursorOff,d2
	moveq	#5,d3
	bsr	PrintText

	movem.l	(a7)+,a0		; CommandStart
	tst.b	(a0)			; If blank commandline, instructions
	beq	HelpText
	cmp.b	#"?",(a0)
	beq	HelpText

ParseStart:
	cmp.b	#"-",(a0)
	beq	CheckOption

Parse:
	cmp.b	#" ",1(a0)		; at least one space after option
	bne	Err_NoComLineSpace
	cmp.b	#"p",(a0)
	beq	FromPCMode
	cmp.b	#"P",(a0)
	beq	ToPCMode
	cmp.b	#"s",(a0)
	beq	FromSF7Mode
	cmp.b	#"S",(a0)
	beq	ToSF7Mode
	cmp.b	#"u",(a0)
	beq	ToUpCaseMode
	cmp.b	#"l",(a0)
	beq	ToLowCaseMode
	cmp.b	#"a",(a0)
	beq	AutoMode
	cmp.b	#"n",(a0)
	beq	ModeToNull
	cmp.b	#"o",(a0)
	beq	ModeToOnlyASCII
	bra	Err_BadMode

CheckOption:
	cmp.b	#"e",1(a0)
	beq	Opt_MakeEOLs
	cmp.b	#"n",1(a0)
	beq	Opt_NoCutSpace
	cmp.b	#"?",1(a0)
	beq	Credits
	cmp.b	#"t",1(a0)
	beq	Opt_TabConv
	cmp.b	#"s",1(a0)
	beq	Opt_SpaceConv
	cmp.b	#"q",1(a0)
	beq	Opt_QuietMode
	cmp.b	#"b",1(a0)
	beq	Opt_NoBufferMode
	bra	Err_BadComLine

Opt_NoCutSpace:
	tst.b	Size_MakeEOLs
	bne	Err_BadLogic
	move.b	#1,Mode_NoCutSpace
	addq.l	#2,a0
	bra	Opt_Next

Opt_TabConv:
	tst.b	TabSize
	bne	Err_BadLogic
	move.b	2(a0),d0
	cmp.b	#" ",d0
	beq	Opt_TabConv1
	sub.b	#"0",d0
	cmp.b	#9,d0
	bhi	Err_BadComLine
	cmp.b	#1,d0
	bcs	Err_BadComLine
	bra	Opt_BothConv

Opt_TabConv1:
	move.b	#8,d0
	subq.l	#1,a0
	bra	Opt_BothConv

Opt_SpaceConv:
	tst.b	TabSize
	bne	Err_BadLogic
	tst.b	Size_MakeEOLs
	bne	Err_BadLogic
	move.b	2(a0),d0
	cmp.b	#" ",d0
	beq	Opt_SpaceConv1
	sub.b	#"0",d0
	cmp.b	#9,d0
	bhi	Err_BadComLine
	cmp.b	#2,d0			; No sense in converting to one tab
	bcs	Err_BadComLine		; so 2 is the lower limit.
	move.b	d0,SpaceSize
	bra	Opt_BothConv

Opt_SpaceConv1:
	move.b	#8,d0
	move.b	d0,SpaceSize
	subq.l	#1,a0

Opt_BothConv:
	move.b	d0,TabSize
	addq.l	#3,a0
	bra	Opt_Next

Opt_QuietMode:
	move.b	#1,Mode_Quiet
	addq.l	#2,a0
	bra	Opt_Next

*** CODE CLEANED UNTIL HERE ***

Opt_MakeEOLs:
	tst.b	SpaceSize
	bne	Err_badlogic
	move.b	2(a0),d0
	cmp.b	#" ",d0
	beq	Err_BadComLine
	sub.b	#"0",d0
	cmp.b	#9,d0
	bhi	Err_BadComLine
	cmp.b	#1,d0
	bcs	Err_BadComLine
	move.b	3(a0),d1
	cmp.b	#" ",d1
	beq	Opt_MakeEOLs1
	sub.b	#"0",d1
	cmp.b	#9,d1
	bhi	Err_BadComLine
	cmp.b	#0,d1
	bcs	Err_BadComLine
	ext.w	d0
	mulu	#10,d0
	add.b	d1,d0
	move.b	d0,size_MakeEOLs
	addq.l	#4,a0
	bra	Opt_Next

Opt_MakeEOLs1:
	move.b	d0,size_MakeEOLs
	addq.l	#3,a0
	bra	Opt_Next

Opt_nobufferMode:
	move.b	#1,Mode_nobuffer
	addq.l	#2,a0

Opt_Next:
	cmp.b	#" ",(a0)
	bne	Err_BadComLine
	bsr	skipspace
	cmp.l	#0,a0
	beq	Err_BadComLine
	bra	parsestart

frompcMode:
	move.b	#1,Mode
	move.l	#table_frompc,table
	bra	nameparse

fromsf7Mode:
	move.b	#2,Mode
	move.l	#table_fromsf7,table
	bra	nameparse

tosf7Mode:
	move.b	#-2,Mode
	move.l	#table_tosf7,table
	bra	nameparse

topcMode:
	move.b	#-1,Mode
	move.l	#table_topc,table
	bra	nameparse

toupcaseMode:
	move.b	#3,Mode
	bra	nameparse

tolowcaseMode:
	move.b	#4,Mode
	bra	nameparse

autoMode:
	tst.b	Mode_nobuffer		; Mode_nobuffer=0? means we have buffer
	bne	Err_needbuffer		; if not
	move.b	#6,Mode
	bra	nameparse

ModeToNull:
	move.b	#5,Mode
	move.l	#table_null,table
	bra	NameParse

ModeToOnlyASCII:
	move.b	#7,Mode
	move.l	#Table_Null,Table

nameparse:
	addq.l	#1,a0			; one after Mode
	bsr	SkipSpace
	cmp.l	#0,a0
	beq	Err_BadComLine
	move.l	a0,sourcenamestart
	bsr	findend
	movem.l	a0,-(a7)		; push sourcename end in stack
	addq.l	#1,a0			; find the length for sourcename
	sub.l	sourcenamestart,a0
	move.l	a0,sourcenamelen

	move.l	sourcenamestart,a0
	move.l	#sourcename,a1
	move.l	sourcenamelen,d0
	bsr	copyname
	clr.b	(a1)

	move.l	#SourceName,d1		; Now let's try to find the source
	move.l	#ACCESS_READ,d2
	move.l	_DosBase,a6
	jsr	_LVOLock(a6)
	move.l	d0,SourceLock
	beq	CheckAllNames		; If no lock, try different suffixes

CheckFile:
	move.l	SourceLock,d1
	move.l	#FIB,d2
	move.l	_DosBase,a6
	jsr	_LVOExamine(a6)
	movem.l	d0,-(a7)		; Save result code

	move.l	SourceLock,d1
	move.l	_DosBase,a6
	jsr	_LVOUnLock(a6)

	movem.l	(a7)+,d0
	tst.l	d0			; Boolean
	beq	Err_SourceCorrupt	; 0 means error
	lea	FIB,a0
	cmp.l	#0,fib_DirEntryType(a0)	; Dir or a file?
	bpl	Err_SourceIsDir		; >=0 means directory, error
	move.l	fib_Size(a0),SourceLen
	move.l	#fib_FileName,a1
	add.l	a0,a1
	move.l	#RealSourceName,a0
	exg	a0,a1
	bsr	CopyUntilNull

	movem.l	(a7)+,a0		; Get SourceName's end from stack
	addq.l	#1,a0
	cmp.l	CommandEnd,a0
	beq	NoDest

	bsr	SkipSpace
	move.l	a0,DestNameStart	; If 0, go NoDest
	beq	NoDest
	bsr	FindEnd
	addq.l	#1,a0			; Add 1 to DestName end, and get
	sub.l	DestNameStart,a0	; DestNameLen in a0
	move.l	a0,d0
	move.l	d0,DestNameLen

	move.l	DestNameStart,a0
	lea	DestName,a1
	bsr	CopyName

	move.l	#DestName,d1		; Now let's try to find the dest
	move.l	#ACCESS_READ,d2
	move.l	_DosBase,a6
	jsr	_LVOLock(a6)
	move.l	d0,DestLock
	beq	OpenFiles		; If no lock, we'll have a file.

	move.l	DestLock,d1		; Otherwise check it
	move.l	#FIB,d2
	move.l	_DosBase,a6
	jsr	_LVOExamine(a6)
	movem.l	d0,-(a7)		; Save result code

	move.l	DestLock,d1
	move.l	_DosBase,a6
	jsr	_LVOUnLock(a6)

	movem.l	(a7)+,d0
	tst.l	d0			; Boolean
	beq	Err_DestCorrupt		; 0 means error

	lea	FIB,a0
	cmp.l	#0,fib_DirEntryType(a0)	; Dir or a file?
	bpl	DestIsDir		; >=0 means directory

	bra	OpenFiles

DestIsDir:
	lea	DestName,a0		; Get DestName
	add.l	DestNameLen,a0		; Go to the end
	cmp.b	#":",-1(a0)		; If the last char is ":",
	beq	LinkName
	cmp.b	#"/",-1(a0)		; or "/" just link the sourcename to it.
	beq	LinkName
	tst.b	-1(a0)
	beq	LinkName
	move.b	#"/",(a0)+

LinkName:
	move.l	#RealSourceName,a1
	exg	a0,a1
	bsr	CopyUntilNull
	bra	OpenFiles

NoDest:
	move.l	SourceNameStart,a0
	move.l	SourceNameLen,d0
	lea	DestName,a1
	bsr	CopyName

	tst.b	Mode_NoBuffer		; If we have a buffer, no suffix, go
	beq	OpenFiles1		; OpenFiles1

	cmp.b	#-1,Mode
	beq	PCSuffix
	cmp.b	#-2,Mode
	beq	SF7Suffix

AmigaSuffix:
	lea	Text_AmigaSuf,a0
	moveq	#4-1,d0
	bra	AddSuffix

PCSuffix:
	lea	Text_PCSuf,a0
	moveq	#3-1,d0
	bra	AddSuffix

SF7Suffix:
	lea	Text_SF7Suf,a0
	moveq	#4-1,d0

AddSuffix:
	move.b	(a0)+,(a1)+
	dbf	d0,AddSuffix

OpenFiles:
	clr.b	(a1)			; End of filename

	tst.b	Mode_NoBuffer
	beq	OpenFiles1

	move.l	#SourceName,d1
	move.l	#MODE_OLDFILE,d2
	move.l	_DosBase,a6
	jsr	_LVOOpen(a6)
	moveq	#1,d7
	move.l	d0,SourceHandle
	beq	CodeError

	move.l	SourceHandle,d1
	move.l	#SourceBuf,d2
	move.l	#4,d3
	move.l	_DosBase,a6
	jsr	_LVORead(a6)
	cmp.l	#4,d0
	bne	OpenFiles3

	move.l	SourceBuf,d0
	cmp.l	#"PP20",d0
	beq	Err_PowerPacked

OpenFiles3:
	move.l	SourceHandle,d1		; seek back to the beginning of file
	sub.l	d2,d2
	moveq	#OFFSET_BEGINNING,d3
	move.l	_DosBase,a6
	jsr	_LVOSeek(a6)

	move.l	#DestName,d1
	move.l	#MODE_NEWFILE,d2
	move.l	_DosBase,a6
	jsr	_LVOOpen(a6)
	move.l	d0,DestHandle
	beq	Err_NoDest

	bra	ReadBlock

CheckAllNames:
	lea	SourceName,a0

CAN_NameLen:
	tst.b	(a0)+			; Loop until null found = end
	bne	CAN_NameLen
	subq.l	#1,a0
	move.l	a0,a2			; Where to add suffixes in a2
	lea	Text_Suffixes,a1

CAN_TrySuffix:
	move.b	(a1)+,(a0)+
	bne	CAN_TrySuffix		; Copy until null moved
	movem.l	a0-a2,-(a7)

	move.l	#SourceName,d1
	move.l	#ACCESS_READ,d2
	move.l	_DosBase,a6
	jsr	_LVOLock(a6)
	move.l	d0,SourceLock
	beq	CAN_NoSuccess		; No lock, try next suffix
	movem.l	(a7)+,a0-a2
	bra	CheckFile
	
CAN_NoSuccess:
	movem.l	(a7)+,a0-a2
	cmp.b	#$ff,(a1)		; $ff = End of suffixes
	beq	Err_NoSource		; If so, couldn't find file
	move.l	a2,a0			; Suffixplace back in a0
	bra	CAN_TrySuffix		; And try again

OpenFiles1:
	lea	SourceLenASCII,a0	; Make a string of the file length
	move.l	SourceLen,d0
	bsr	Num2ASCII
	move.l	a0,SourceLenASCIIAddr
	move.l	d0,SourceLenASCIILen

	move.l	#SourceName,d1
	move.l	#MODE_OLDFILE,d2
	move.l	_DosBase,a6
	jsr	_LVOOpen(a6)
	moveq	#2,d7
	move.l	d0,SourceHandle
	beq	CodeError

	move.l	SourceHandle,d1
	move.l	#SourceBuf,d2
	move.l	#4,d3
	move.l	_DosBase,a6
	jsr	_LVORead(a6)
	cmp.l	#4,d0
	bne	OpenFiles2

	move.l	SourceBuf,d0
	cmp.l	#"PP20",d0
	beq	Err_PowerPacked

OpenFiles2:
	move.l	SourceHandle,d1		; seek back to the beginning of file
	sub.l	d2,d2
	moveq	#OFFSET_BEGINNING,d3
	move.l	_DosBase,a6
	jsr	_LVOSeek(a6)

	move.l	SourceLen,d0
	moveq	#MEMF_PUBLIC,d1
	move.l	ExecBase,a6
	jsr	_LVOAllocMem(a6)
	move.l	d0,SourcePointer
	beq	Err_NoMem

ReadFile:
	move.l	SourceHandle,d1
	move.l	SourcePointer,d2
	add.l	ReadBytes,d2
	move.l	#10240,d3
	move.l	_DosBase,a6
	jsr	_LVORead(a6)
	cmp.l	#-1,d0
	beq	Err_ReadFail
	add.l	d0,ReadBytes
	movem.l	d0,-(a7)
	tst.b	Mode_Quiet
	bne	TestRead

	move.l	#Text_Read,d2
	moveq	#14,d3
	bsr	PrintText

	lea	ReadASCII,a0
	move.l	ReadBytes,d0
	bsr	Num2ASCII

	move.l	a0,ReadASCIIAddr
	move.l	d0,ReadASCIILen
	move.l	a0,d2
	move.l	d0,d3
	bsr	PrintText

	move.l	#Text_Slash,d2
	moveq	#1,d3
	bsr	PrintText

	move.l	SourceLenASCIIAddr,d2
	move.l	SourceLenASCIILen,d3
	bsr	PrintText

	move.l	#Text_CR,d2
	moveq	#1,d3
	bsr	PrintText

TestRead:
	movem.l	(a7)+,d0
	tst.l	d0			; = number of bytes read
	beq	ReadFinished

	sub.l	d0,d0
	sub.l	d1,d1
	move.l	ExecBase,a6
	jsr	_LVOSetSignal(a6)

	btst	#SIGBREAKB_CTRL_C,d0	; check if ^C was pressed
	bne	BreakPressed

	bra	ReadFile

ReadFinished:
	move.l	ReadBytes,LeftBytes

	move.l	SourceHandle,d1
	move.l	_DosBase,a6
	jsr	_LVOClose(a6)

	cmp.b	#6,Mode			; AutoMode on?
	beq	DetectMode

ReadFinished1:
	move.l	#DestName,d1
	move.l	#MODE_NEWFILE,d2
	move.l	_DosBase,a6
	jsr	_LVOOpen(a6)
	move.l	d0,DestHandle
	beq	Err_NoDest

	bra	MoreData

DetectMode:
	move.l	#Text_Checking,d2
	moveq	#34,d3
	bsr	PrintText

	sub.l	d2,d2
	sub.l	d3,d3
	sub.l	d4,d4
	move.l	SourcePointer,a0
	cmp.l	#10240,LeftBytes
	bcs	DetectMode1
	move.l	#10240-1,d1

DetectMode2:
	move.b	(a0)+,d0
	cmp.b	#"{",d0
	beq	DM_sf7
	cmp.b	#"[",d0
	beq	DM_sf7
	cmp.b	#"|",d0
	beq	DM_sf7
	cmp.b	#"\",d0
	beq	DM_sf7

	cmp.b	#"ä",d0
	beq	DM_Amy
	cmp.b	#"Ä",d0
	beq	DM_Amy
	cmp.b	#"ö",d0
	beq	DM_Amy
	cmp.b	#"Ö",d0
	beq	DM_Amy

	cmp.b	#$84,d0
	beq	DM_PC
	cmp.b	#$8e,d0
	beq	DM_PC
	cmp.b	#$94,d0
	beq	DM_PC
	cmp.b	#$99,d0
	beq	DM_PC

	cmp.b	#13,d0
	beq	DM_foreign

DetectMode3:
	dbf	d1,DetectMode2

	cmp.l	d2,d3
	beq	SameWarn1
	cmp.l	d2,d4
	beq	SameWarn1
	cmp.l	d3,d4
	beq	SameWarn2

DetectMode4:
	movem.l	d2-d4,-(a7)
	move.l	#Text_Uses,d2
	moveq	#14,d3
	bsr	PrintText
	movem.l	(a7)+,d2-d4

	cmp.l	d2,d3			; SF7 or Amy
	bhi	DM_NotSF7

DM_NotAmy:
	cmp.l	d2,d4			; SF7 or PC
	bhi	DM_MakePC
	bra	DM_MakeSF7

DM_NotSF7:
	cmp.l	d3,d4			; Amy or PC
	bhi	DM_MakePC

DM_MakeAmy:
	move.b	#5,Mode
	move.l	#Table_Null,Table

	move.l	#Text_NullMode,d2
	moveq	#10,d3
	bsr	PrintText

	bra	ReadFinished1	

DM_MakePC:
	move.b	#1,Mode
	move.l	#Table_FromPC,Table

	move.l	#Text_PCMode,d2
	moveq	#7,d3
	bsr	PrintText

	bra	ReadFinished1

DM_MakeSF7:
	move.b	#2,Mode
	move.l	#Table_FromSF7,Table

	move.l	#Text_SF7Mode,d2
	moveq	#8,d3
	bsr	PrintText

	bra	ReadFinished1

SameWarn1:
	cmp.l	d3,d4
	beq	Err_SameProbability
	bra	DetectMode4

SameWarn2:
	cmp.l	d2,d3
	beq	Err_SameProbability
	bra	DetectMode4

DetectMode1:
	move.l	LeftBytes,d1
	subq.l	#1,d1
	bra	DetectMode2

DM_SF7:
	addq.l	#1,d2
	bra	DetectMode3

DM_Amy:
	addq.l	#1,d3
	bra	DetectMode3

DM_PC:
	addq.l	#1,d4
	bra	DetectMode3

DM_Foreign:
	addq.l	#1,d2
	addq.l	#1,d4
	bra	DetectMode3

ReadBlock:
	tst.b	Mode_NoBuffer
	beq	MoreData

	move.l	SourceHandle,d1
	move.l	SourcePointer,d2
	move.l	#1024,d3
	move.l	_DosBase,a6
	jsr	_LVORead(a6)
	cmp.l	#-1,d0
	beq	Err_ReadFail
	add.l	d0,ReadBytes
	move.l	d0,d1
	beq	CloseFiles		; ReadBytes = 0 - Quit
	subq.l	#1,d1			; Counter always one less than real
	sub.l	d2,d2			; Bytes to be written zeroed
	lea	SourceBuf,a0
	lea	DestBuf,a1
	bra	MoreCharacters

MoreData:
	tst.l	LeftBytes
	beq	CloseFiles
	sub.l	d2,d2
	cmp.l	#1024,LeftBytes
	bls	MoreData1
	sub.l	#1024,LeftBytes
	move.l	SourcePointer,a0
	add.l	InputBytes,a0
	add.l	#1024,InputBytes
	move.l	#1024-1,d1
	lea	DestBuf,a1
	bra	MoreCharacters

MoreData1:
	move.l	LeftBytes,d0
	clr.l	LeftBytes
	move.l	SourcePointer,a0
	add.l	InputBytes,a0
	add.l	d0,InputBytes
	subq.l	#1,d0
	move.l	d0,d1
	lea	DestBuf,a1

MoreCharacters:
	move.b	(a0)+,d0

	tst.b	Mode			; ToSF7 = -2, ToPC = -1
	bmi	Translate		; Lower than 0

	cmp.b	#2,Mode			; FromSF7
	beq	translate
	cmp.b	#3,Mode			; Upcase
	beq	toupcase
	cmp.b	#4,Mode			; Lowcase
	beq	tolowcase
	cmp.b	#5,Mode			; Null
	beq	translate
	cmp.b	#7,Mode			; OnlyASCII
	beq	OnlyASCIIMode

FromPC:
	cmp.b	#" ",d0
	bcs	PC_Translate
	cmp.b	#"~",d0
	bhi	PC_Translate
	bra	NextChar

PC_Translate:
	tst.b	d0			; The two characters not in the table
	beq	NoChar
	cmp.b	#$1a,d0
	beq	NoChar
	cmp.b	#13,d0			; CRs out!
	beq	NoChar
	cmp.b	#$80,d0
	bcs	NextChar
	lea	Table_FromPC,a3
	sub.b	#$80,d0
	ext.w	d0
	ext.l	d0
	add.l	d0,a3
	move.b	(a3),d0
	beq	NoChar
	bra	CutSpace

translate:
	move.l	table,a3
	tst.b	d0
	beq	NoChar

translate1:
	move.w	(a3)+,d3
	beq	NextChar		; 0 = End of table
	cmp.b	d3,d0
	beq	translate2
	bra	translate1

translate2:
	lsr.w	#8,d3
	move.b	d3,d0			; If 0 = No char
	beq	nochar

NextChar:
	bra	CutSpace

checknormal:
	move.b	d0,(a1)+
	addq.l	#1,d2
	addq.w	#1,col

NoChar:
	dbf	d1,MoreCharacters

	move.l	DestHandle,d1		; Write the converted data
	move.l	d2,d3
	add.l	d2,WrittenBytes
	move.l	#DestBuf,d2
	move.l	_DosBase,a6
	jsr	_LVOWrite(a6)
	cmp.l	#-1,d0
	beq	Err_WriteFail

	sub.l	d0,d0
	sub.l	d1,d1
	move.l	ExecBase,a6
	jsr	_LVOSetSignal(a6)

	btst	#SIGBREAKB_CTRL_C,d0	; check if ^C was pressed
	bne	EndProgram5

	tst.b	Mode_Quiet
	bne	ReadBlock

	tst.b	Mode_NoBuffer
	beq	AlternateOutput

	move.l	#Text_Input,d2
	moveq	#15,d3
	bsr	PrintText

	lea	NumberBuf,a0
	move.l	ReadBytes,d0
	bsr	Num2ASCII

	move.l	a0,d2
	move.l	d0,d3
	bsr	PrintText

	move.l	#Text_Output,d2
	moveq	#18,d3
	bsr	PrintText

	lea	numberbuf,a0
	move.l	writtenbytes,d0
	bsr	num2ascii

	move.l	a0,d2
	move.l	d0,d3
	bsr	PrintText

	move.l	#Text_CR,d2
	moveq	#1,d3
	bsr	PrintText

	bra	ReadBlock

alternateoutput:
	move.l	#Text_converted,d2
	moveq	#19,d3
	bsr	PrintText

	lea	numberbuf,a0
	move.l	inputbytes,d0
	bsr	num2ascii

	move.l	a0,d2
	move.l	d0,d3
	bsr	PrintText

	move.l	#Text_slash,d2
	moveq	#1,d3
	bsr	PrintText

	move.l	readasciiaddr,d2
	move.l	readasciilen,d3
	bsr	PrintText

	move.l	#Text_cr,d2
	moveq	#1,d3
	bsr	PrintText

	bra	readblock

cutspace:
	move.l	spacepointer,a2
	cmp.b	#" ",d0
	beq	addspace
	cmp.b	#9,d0			; tab
	beq	addtab
	bsr	addEOL			; check if char is 10, and add EOLs

	tst.b	Mode_nocutspace
	bne	cutspace2

	cmp.b	#10,d0			; lf
	beq	cutspaces

cutspace1:				; a character which is not a space,
	tst.b	prespace		; tab or a linefeed.  Trigger things
	bne	insertprespace
	tst.l	tabs
	bne	linkspaces

cutspace3:
	tst.l	spacenumber
	bne	linkspaces2

cutspace4:
	cmp.b	#10,d0			; has been buffered, nochar
	beq	nochar
	tst.b	Mode_nocutspace
	beq	testforspace

linkEOLs:
	bsr	insertEOLs		; insert any EOLs currently in buffer

	cmp.b	#" ",d0			; if the char was a space or a tab,
	beq	nochar			; we don't want it to pass straight
	cmp.b	#9,d0			; in the buffer.  otherwise yes.
	beq	nochar
	bra	checknormal

testforspace:
	cmp.b	#" ",d0			; if cutspace is on, spaces and tabs
	beq	nochar			; don't automatically trigger EOLs
	cmp.b	#9,d0			; in: they will be triggered when
	beq	nochar			; the tabs and spaces get triggered
	bra	linkEOLs

cutspace2:
	cmp.b	#10,d0
	bne	cutspace1
	clr.w	col
	bra	cutspace1

addspace:
	move.b	d0,(a2)+
	move.l	a2,spacepointer
	addq.l	#1,spacenumber
	addq.w	#1,col
	bra	checkconvspace

addtab:
	move.b	TabSize,d4		; if TabSize is zero, just add it in
	bne	tabconv			; spacebuffer
	bra	addspace

tabconv:
	ext.w	d4			; Convert TabSize
	ext.l	d4
	move.w	Col,d3			; Get current column
	ext.l	d3
	divu	d4,d3			; Divide column with TabSize -> we get
	swap	d3			; the offset from last tab as characters
	sub.w	d3,d4			; Get the # of spaces to the next tab
	add.l	d4,SpaceNumber
	add.w	d4,col
	subq.w	#1,d4
	move.b	#" ",d0

TabConv1:
	move.b	d0,(a2)+		; Copy the spaces in the buffer
	dbf	d4,TabConv1
	move.l	a2,SpacePointer		; And save the space buf pointer

CheckConvSpace:
	tst.b	SpaceSize		; SpaceSize=0 means no space2tab
	beq	cutspace4
	cmp.l	#1,spacenumber		; if spacenumber<1, skip
	bcs	cutspace4
	move.w	col,d5
	ext.l	d5
	move.l	spacenumber,d3
	move.b	SpaceSize,d4
	ext.w	d4
	ext.l	d4

	divu	d4,d5			; if column is divisible by SpaceSize,
	swap	d5			; go to "foundconvspace"
	tst.w	d5
	beq	foundconvspace
	bra	cutspace4		; otherwise just continue

foundconvspace:
	cmp.l	#1,spacenumber		; if only one space is won, don't
	beq	foundconvspace2
	move.l	#spacebuf,spacepointer
	addq.l	#1,tabs
	sub.l	d4,spacenumber
	bmi	foundconvspace1
	bra	cutspace4

foundconvspace1:
	clr.l	spacenumber
	bra	cutspace4

foundconvspace2:
	move.b	#1,prespace
	move.l	#spacebuf,spacepointer
	clr.l	spacenumber
	bra	cutspace4

cutspaces:
	clr.b	PreSpace
	clr.l	spacenumber
	clr.l	tabs
	move.l	#spacebuf,spacepointer
	clr.w	col
	bra	nochar

AddEOL:
	cmp.b	#10,d0
	beq	addEOL1
	rts

addEOL1:
	addq.l	#1,EOLs
	rts

linkspaces:
	tst.b	Mode_nocutspace
	bne	linkspaces4
	bsr	insertEOLs

linkspaces4:
	move.l	tabs,d3
	clr.l	tabs
	add.l	d3,d2			; tabs -> bytes to be written
	subq.l	#1,d3

linkspaces1:
	move.b	#9,(a1)+
	dbf	d3,linkspaces1
	bra	cutspace3

linkspaces2:
	tst.b	Mode_nocutspace
	bne	linkspaces5
	bsr	insertEOLs

linkspaces5:
	move.l	spacenumber,d3
	tst.b	size_MakeEOLs
	bne	ls_checkMakeEOLs
linkspaces6:
	add.l	d3,d2			; spaces -> bytes to be written
	subq.l	#1,d3
	lea	spacebuf,a2
	move.l	a2,spacepointer

linkspaces3:
	move.b	(a2)+,(a1)+
	dbf	d3,linkspaces3
	clr.l	spacenumber
	bra	cutspace4

LS_CheckMakeEOLs:
	cmp.b	size_MakeEOLs,d3
	bcs	linkspaces6
	addq.l	#1,d2
	move.b	#10,(a1)+
	clr.l	spacenumber
	move.l	#spacebuf,spacepointer
	bra	cutspace4

insertprespace:
	clr.b	prespace
	move.b	#" ",(a1)+
	addq.l	#1,d2
	bra	cutspace1

toupcase:
	cmp.b	#"ä",d0
	beq	Amy_upae
	cmp.b	#"ö",d0
	beq	Amy_upoe
	cmp.b	#"a",d0
	bcs	Nextchar
	cmp.b	#"z",d0
	bhi	Nextchar

	and.b	#%11011111,d0
	bra	Nextchar

tolowcase:
	cmp.b	#"Ä",d0
	beq	Amy_lowae
	cmp.b	#"Ö",d0
	beq	Amy_lowoe
	cmp.b	#"A",d0
	bcs	Nextchar
	cmp.b	#"Z",d0
	bhi	Nextchar

	or.b	#%100000,d0
	bra	Nextchar

OnlyASCIIMode:
	btst	#7,d0
	bne	NoChar
	bra	Translate

Amy_lowae:
	move.b	#"ä",d0
	bra	Nextchar

Amy_lowoe:
	move.b	#"ö",d0
	bra	Nextchar

Amy_upae:
	move.b	#"Ä",d0
	bra	Nextchar

Amy_upoe:
	move.b	#"Ö",d0
	bra	Nextchar

closefiles:
	tst.b	Mode_nobuffer
	beq	freebuffer
	bsr	closesource
	bra	closefiles3

freebuffer:
	bsr	freememory

closefiles3:
	bsr	closedest

	move.l	#Text_final,d2
	moveq	#26,d3
	bsr	PrintText

	move.l	readbytes,d1
	move.l	writtenbytes,d0

	sub.l	d1,d0
	bmi	closefiles1		; Negative

	move.l	d0,d7
	beq	closefiles2		; If zero, no sign

	move.l	#Text_possign,d2
	moveq	#1,d3
	bsr	PrintText
	bra	closefiles2

closefiles1:
	neg.l	d0
	move.l	d0,d7

	move.l	#Text_negsign,d2
	moveq	#1,d3
	bsr	PrintText

closefiles2:
	move.l	d7,d0
	lea	numberbuf,a0
	bsr	num2ascii

	move.l	a0,d2
	move.l	d0,d3
	bsr	PrintText

	move.l	#Text_doublespace,d2
	moveq	#2,d3
	bsr	PrintText

	move.l	writtenbytes,d0
	move.l	readbytes,d1
	bsr	percentage

	lea	numberbuf,a0
	bsr	num2ascii

	move.l	a0,d2
	move.l	d0,d3
	bsr	PrintText

	move.l	#Text_percentsign,d2
	move.l	#5,d3
	bsr	PrintText

	move.l	#Text_lf,d2
	move.l	#1,d3
	bsr	PrintText
	bra	EndProgram1

helptext:
	move.l	#Text_helptext,d2
	move.l	#len_helptext,d3
	bsr	PrintText
	bra	EndProgram1

credits:
	move.l	#Text_credits,d2
	move.l	#len_credits,d3
	bsr	PrintText
	bra	EndProgram1

CodeError:
	movem.l	d7,-(a7)
	move.l	#Text_CodeError,d2
	move.l	#Len_CodeError,d3
	bsr	PrintText
	lea	NumberBuf,a0
	movem.l	(a7)+,d0
	bsr	Num2ASCII
	move.l	a0,d2
	move.l	d0,d3
	bsr	PrintText
	bra	EndProgram1

	IF	TestMode=1

Err_TestMode:
	move.l	#$ffff,d0

Err_TestMode1:
	move.w	#$f00,$dff180
	dbf	d0,Err_TestMode1
	bra	EndProgram1

	ENDC

Err_NoSource:
	move.l	#Text_NoSource,d2
	moveq	#28,d3
	bsr	PrintError
	bra	EndProgram1

Err_BadComLine:
	move.l	#Text_BadComLine,d2
	moveq	#17,d3
	bsr	printerror
	bra	EndProgram1

Err_NoDest:
	move.l	#Text_nodest,d2
	moveq	#33,d3
	bsr	printerror
	bra	EndProgram2

Err_badMode:
	move.l	#Text_badMode,d2
	moveq	#24,d3
	bsr	printerror
	bra	EndProgram1

Err_nocomlinespace:
	move.l	#Text_nocomlinespace,d2
	moveq	#52,d3
	bsr	printerror
	bra	EndProgram1

Err_badlogic:
	move.l	#Text_badlogic,d2
	moveq	#25,d3
	bsr	printerror
	bra	EndProgram1

Err_nomem:
	move.l	#Text_nomemory,d2
	moveq	#36,d3
	bsr	printerror
	bsr	closesource
	bra	EndProgram1

Err_powerpacked:
	move.l	#Text_powerpacked,d2
	moveq	#48,d3
	bsr	printerror
	bsr	closesource
	bra	EndProgram1

Err_seekfail:
	move.l	#Text_badsource,d2
	moveq	#23,d3
	bsr	printerror
	bsr	closesource
	bra	EndProgram1

Err_readfail:
	move.l	#Text_badsource,d2
	moveq	#23,d3
	bsr	printerror
	bra	EndProgram3

Err_SourceCorrupt:
	move.l	#Text_BadSource,d2
	moveq	#23,d3
	bsr	PrintError
	bra	EndProgram1

Err_DestCorrupt:
	move.l	#Text_BadDest,d2
	moveq	#23,d3
	bsr	PrintError
	bra	EndProgram1

Err_SourceIsDir:
	move.l	#Text_SourceIsDir,d2
	moveq	#28,d3
	bsr	PrintError
	bra	EndProgram1

Err_WriteFail:
	move.l	#Text_WriteFail,d2
	moveq	#18,d3
	bsr	printerror
	bra	EndProgram3

Err_needbuffer:
	move.l	#Text_needbuffer,d2
	moveq	#42,d3
	bsr	printerror
	bra	EndProgram1

Err_sameprobability:
	move.l	#Text_sameprobability,d2
	moveq	#28,d3
	bsr	printerror
	bsr	freememory
	bra	EndProgram1

EndProgram5:
	tst.b	Mode_nobuffer
	beq	EndProgram6

	bsr	closesource
	bsr	closedest

	move.l	#destname,d1
	move.l	_DosBase,a6
	jsr	_LVODeleteFile(a6)		; *!* Error detection here

	move.l	#Text_break,d2
	moveq	#20,d3
	bsr	PrintText
	bra	EndProgram1

EndProgram6:
	bsr	closedest
	bsr	freememory

	move.l	#destname,d1
	move.l	_DosBase,a6
	jsr	_LVODeleteFile(a6)		; error detection here

	move.l	#Text_break,d2
	moveq	#20,d3
	bsr	PrintText
	bra	EndProgram1

breakpressed:				; source and mem open, dest not
	bsr	freememory
	bsr	closesource
	move.l	#Text_break,d2
	moveq	#20,d3
	bsr	PrintText
	bra	EndProgram1

	bsr	closedest

EndProgram3:
	bsr	closesource
	tst.b	Mode_nobuffer
	beq	EndProgram3_1
	bsr	closedest
	bra	EndProgram1

EndProgram3_1:
	bsr	freememory
	bra	EndProgram1

EndProgram2:
	tst.l	SourceHandle		; closes source if it's open
	beq	EndProgram1
	bsr	CloseSource

EndProgram1:
	move.l	#Text_cursoron,d2
	moveq	#5,d3
	bsr	PrintText

	move.l	ExecBase,a6
	move.l	_DosBase,a1
	jsr	_LVOCloseLibrary(a6)
	sub.l	d0,d0
	move.l	OldStack,a7
	rts


**********
** SUBS **
**********

insertEOLs:
	move.l	EOLs,d3
	bne	insertEOLs1
	rts

insertEOLs1:
	add.l	d3,d2
	subq.l	#1,d3

insertEOLs2:
	cmp.b	#0,Mode		; if Mode is negative, adds crs
	bmi	insertcr
insertEOLs3:
	move.b	#10,(a1)+
	dbf	d3,insertEOLs2
	clr.l	EOLs
	rts

InsertCR:
	move.b	#13,(a1)+
	addq.l	#1,d2
	bra	InsertEOLs3

freememory:
	move.l	sourcepointer,a1
	move.l	sourcelen,d0
	move.l	ExecBase,a6
	jsr	_LVOFreeMem(a6)
	rts

closedest:
	move.l	desthandle,d1
	move.l	_DosBase,a6
	jsr	_LVOClose(a6)
	rts

closesource:
	move.l	sourcehandle,d1
	move.l	_DosBase,a6
	jsr	_LVOclose(a6)
	rts

printerror:
	movem.l	d2/d3,-(a7)
	move.l	#Text_error,d2
	move.l	#8,d3
	bsr	PrintText
	movem.l	(a7)+,d2/d3
	bsr	PrintText
	rts

PrintText:
	if	testMode=1
	rts
	endc

	move.l	outstruct,d1
	move.l	_DosBase,a6
	jsr	_LVOwrite(a6)
	rts

SkipSpace:
	cmp.b	#" ",(a0)
	beq	SkipSpace1
	rts

SkipSpace1:
	addq.l	#1,a0
	cmp.l	CommandEnd,a0
	bcs	SkipSpace
	sub.l	a0,a0
	rts

FindEnd:
	cmp.b	#'"',(a0)		; If the first letter is a quote,
	beq	FindEnd_Quote		; go to FindEnd_Quote

FindEnd_Space:
	addq.l	#1,a0			; Get the next position, if it is a
	cmp.b	#" ",(a0)		; space, we found the end
	beq	FindEnd_Space1
	tst.b	(a0)			; If it's the end of comline, we found
	beq	FindEnd_Space1		; the end of name
	bra	FindEnd_Space

FindEnd_Space1:
	subq.l	#1,a0
	rts

FindEnd_Quote:
	addq.l	#1,a0
	tst.b	(a0)			; If end of comline, error
	beq	FindEnd_Quote2
	cmp.b	#'"',(a0)
	bne	FindEnd_Quote
	rts

FindEnd_Quote2:
	sub.l	a0,a0
	rts

CopyUntilNull:
	move.b	(a0)+,(a1)+
	bne	CopyUntilNull
	rts

	INCDIR	"SRC:Routines/"
	INCLUDE	"Num2ASCII.S"
	INCLUDE	"Percentage.S"
	INCLUDE	"CopyName.S"

**********
** DATA **
**********

	section	fastdata,data

SourcePointer:
	dc.l	SourceBuf

SpacePointer:
	dc.l	SpaceBuf

***********************
** Conversion tables **
***********************

; The byte from which to convert is on the right, and the byte into which it
; turns is on the left.  If a null is on the left, it means the byte doesn't
; get to the destination file at all.


table_topc:
	dc.b	$00,$0d
	dc.b	$00,$1a
	dc.b	$84,"ä"
	dc.b	$8e,"Ä"
	dc.b	$94,"ö"
	dc.b	$99,"Ö"
	dc.w	0

table_null:
	dc.b	$00,$0d
	dc.b	$00,$1a
	dc.w	0

table_tosf7:
	dc.b	$00,$0d
	dc.b	$00,$1a
	dc.b	"{","ä"
	dc.b	"|","ö"
	dc.b	"[","Ä"
	dc.b	"\","Ö"
	dc.w	0

table_fromsf7:
	dc.b	$00,$0d
	dc.b	$00,$1a
	dc.b	"ä","{"
	dc.b	"ö","|"
	dc.b	"Ä","["
	dc.b	"Ö","\"
	dc.w	0

Table_FromPC:	; 0  1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
	dc.b	"Ç","ü","e","å","ä","a","a","ç","ê","ë","e","ï","î","i","Ä","a"
	dc.b	"E","æ","Æ","ô","ö","o","û","u","ÿ","Ö","ü",$a2,"£",$a5,"P","f"
	dc.b	"a","i","o","u","n","N","ª","º","¿","+","+","½","¼",$a1,"«","»"
	dc.b	$7f,$7f,$7f,"|","+","#","#","+","#","#","|","#","#","+","+","+"
	dc.b	"+","+","+","+","-","+","#","#","#","#","#","#","#","=","#","#"
	dc.b	"#","+","+","+","+","+","+","#","#","+","+",$7f,"æ","[","]","^"
	dc.b	"c","ß","r","#","E","ó","y","i","o","0","o","ð","°","0","E","A"
	dc.b	"=","±",">","<","í","j","÷","~","°","·","·","V","n","²","·"," "

	INCDIR	"SRC:Port/"

Text_CodeError:
	INCBIN	"PortCodeError"

Text_helptext:
	INCBIN	"PortOpts1"		; Don't change the way these lines are
					; arranged!
Text_credits:
	INCBIN	"PortOpts2"

Text_CursorOff:
	dc.b	27,"[0 p"

Text_CursorOn:
	dc.b	27,"[1 p"

Text_Error:
	dc.b	"ERROR!  "

Text_BadComLine:
	dc.b	"Bad commandline.",10

Text_NoSource:
	dc.b	"Could not open source file.",10

Text_NoDest:
	dc.b	"Could not open destination file.",10

Text_SourceIsDir:
	dc.b	"Source file is a directory.",10

Text_badMode:
	dc.b	"Bad mode specification.",10

Text_WriteFail:
	dc.b	"Can't write data.",10

Text_nocomlinespace:
	dc.b	"The mode must be separated with at least one space.",10

Text_badlogic:
	dc.b	"Conflict in commandline.",10

Text_nomemory:
	dc.b	"Not enough memory to load the file.",10

Text_powerpacked:
	dc.b	"File is a PowerPacker data file, can't process.",10

Text_badsource:
	dc.b	"Source file corrupted.",10

Text_BadDest:
	dc.b	"Destination corrupted.",10

Text_needbuffer:
	dc.b	"Auto-mode only works with buffered input.",10

Text_SameProbability:
	dc.b	"Can't decide between modes.",10

Text_input:
	dc.b	27,"[1mInput:",27,"[0m "

Text_output:
	dc.b	"  ",27,"[1mOutput:",27,"[0m "

Text_read:
	dc.b	27,"[1mRead:",27,"[0m "

Text_converted:
	dc.b	27,"[1mConverted:",27,"[0m "

Text_checking:
	dc.b	27,"[1mChecking file type...",27,"[0m",27,"[0K",13

Text_uses:
	dc.b	27,"[1mType:",27,"[0m "

Text_nullMode:
	dc.b	"Amiga",27,"[0K",10

Text_sf7Mode:
	dc.b	"SF7",27,"[0K",10

Text_PCMode:
	dc.b	"PC",27,"[0K",10

Text_break:
	dc.b	27,"[1m-BREAK-",27,"[0m",27,"[0K",10

Text_clearEOL:
	dc.b	27,"[0K"

_DosName:
	dc.b	"dos.library",0

Text_amigasuf:
	dc.b	".AMY"

Text_PCsuf:
	dc.b	".PC"

Text_sf7suf:
	dc.b	".SF7"

Text_CR:
	dc.b	13

Text_LF:
	dc.b	10

Text_Final:
	dc.b	27,"[1mFile size change:",27,"[0m "

Text_negsign:
	dc.b	"-"

Text_possign:
	dc.b	"+"

Text_percentsign:
	dc.b	"%",27,"[0K"

Text_doublespace:
	dc.b	"  "

Text_slash:
	dc.b	"/"

Text_Suffixes:
	dc.b	".TXT",0
	dc.b	".DOC",0
	dc.b	".AMY",0
	dc.b	".SF7",0
	dc.b	".PC",0
	dc.b	".ASC",0
	dc.b	".ANS",0
	dc.b	".LST",0
	dc.b	".NFO",0
	dc.b	$ff

	IF	TestMode=1

Test_ComLine:
	dc.b	'P ram:ankka1 ram:shit',10

Test_ComLineEnd:

Test_Len	=	Test_ComLineEnd-Test_ComLine

	ENDC

	SECTION	FastBlank,BSS

FIB:
	ds.b	fib_SIZEOF

OldStack:
	ds.l	1

DestNameLen:
	ds.l	1

SourceLock:
	ds.l	1

DestLock:
	ds.l	1

Eols:
	ds.l	1

Readasciiaddr:
	ds.l	1

Table:
	ds.l	1

Sourcelen:
	ds.l	1

Tabs:
	ds.l	1

Writtenbytes:
	ds.l	1

Readbytes:
	ds.l	1

Leftbytes:
	ds.l	1

Inputbytes:
	ds.l	1

Sourcehandle:
	ds.l	1

Desthandle:
	ds.l	1

Outstruct:
	ds.l	1

Destnamestart:
	ds.l	1

Sourcenamestart:
	ds.l	1

Sourcenamelen:
	ds.l	1

Commandstarrt:
	ds.l	1

Commandend:
	ds.l	1

Commandlen:
	ds.l	1

_DosBase:
	ds.l	1

Spacenumber:
	ds.l	1

Readasciilen:
	ds.l	1

Sourcelenasciilen:
	ds.l	1

Sourcelenasciiaddr:
	ds.l	1

Col:
	ds.w	1

Sourcebuf:
	ds.b	1024

RealSourceName:
	ds.b	108			; Max filename size in FIB

Sourcename:
	ds.b	256

Destname:
	ds.b	256

Destbuf:
	ds.b	9216

Spacebuf:
	ds.b	1024

Numberbuf:
	ds.b	10

Readascii:
	ds.b	10

Sourcelenascii:
	ds.b	10

Mode:
	ds.b	1

TabSize:
	ds.b	1

SpaceSize:
	ds.b	1

size_MakeEOLs:
	ds.b	1

prespace:
	ds.b	1

Mode_case:
	ds.b	1

Mode_nocutspace:
	ds.b	1

Mode_Quiet:
	ds.b	1

Mode_nobuffer:
	ds.b	1

Len_CodeError	=	Text_HelpText-Text_CodeError
Len_HelpText	=	Text_Credits-Text_HelpText
Len_Credits	=	Text_CursorOff-Text_Credits
