	opt	c+,d+
;---------------------------------------------------------
	incdir	"ram:Labels/"
	include	Exec
	include	Libraries
;---------------------------------------------------------
	movem.l	d0-d7/a0-a6,-(sp)
;---------------------------------------------------------
	move.l	ExecBase,a6
	lea	DataTable(pc),a5
;---------------------------------------------------------
	lea	DosName(pc),a1
	clr.l	d0
	call	OpenLibrary
	move.l	d0,DosBase(a5)
;---------------------------------------------------------
	move.l	d0,a6
	lea	FileIn(pc),a0
	move.l	a0,d1
	move.l	#ACCESS_READ,d2
	call	Lock
	move.l	d0,Lock(a5)
;---------------------------------------------------------
	move.l	d0,d1
	lea	FIB(a5),a0
	move.l	a0,d2
	call	Examine
;---------------------------------------------------------
	move.l	fib_Size(a5),d0	;FIB first in table ...
	move.l	d0,Size(a5)
	move.l	#MEMF_CHIP,d1
	move.l	ExecBase,a6
	call	AllocMem
	move.l	d0,Buffer(a5)
;---------------------------------------------------------
	move.l	DosBase(a5),a6
	move.l	Lock(a5),d1
	call	UnLock
;---------------------------------------------------------
	lea	FileIn(pc),a0
	move.l	a0,d1
	move.l	#MODE_OLDFILE,d2
	call	Open
	move.l	d0,File(a5)
;---------------------------------------------------------
	move.l	d0,d1
	move.l	Buffer(a5),d2
	move.l	Size(a5),d3
	call	Read
;---------------------------------------------------------
	move.l	File(a5),d1
	call	Close
;---------------------------------------------------------
	move.l	Size(a5),d7
	subq.l	#1,d7	;d7=counter
	moveq	#24,d6	;d6=new lenght (24 leading spaces)
	move.l	Buffer(a5),a0
	move.l	a0,a1	;a0=old/a1=new pointer to text
;---------------------------------------------------------
FixText:	move.b	(a0)+,d0
	ext.w	d0
	cmp.w	#$20,d0
	blt.s	Skip	
	cmp.w	#$60,d0
	blt.s	Store
	cmp.w	#$80,d0
	bge.s	Skip
	sub.w	#$20,d0
	bra.s	Store
Skip:	move.w	#$20,d0
Store:	move.b	d0,(a1)+
	addq.l	#1,d6
	dbra	d7,FixText
;---------------------------------------------------------
	move.l	d6,d0
	lsl.l	#4,d0	;x16
	lea	HITEXT(pc),a0
	move.l	d0,(a0)
;---------------------------------------------------------
	move.l	d6,d0
	lea	ENDTEXT(pc),a0
	move.l	d0,(a0)
;---------------------------------------------------------
	move.l	d6,d0
	addq.l	#3,d0	;number of long words
	lsr.l	#2,d0	
	lea	LongSize(pc),a0
	move.l	d0,(a0)
	move.l	Size(a5),d0
	addq.l	#3,d0
	and.l	#$fffc,d0
	move.l	d0,d5	;d5=number of 'long bytes'
;---------------------------------------------------------
	lea	FileOut(pc),a0
	move.l	a0,d1
	move.l	#MODE_NEWFILE,d2
	call	Open
	move.l	d0,File(a5)
;---------------------------------------------------------
	move.l	File(a5),d1
	lea	Hunk1(pc),a0
	move.l	a0,d2
	move.l	#Hunk2-Hunk1,d3
	call	Write
;---------------------------------------------------------
	move.l	File(a5),d1
	move.l	Buffer(a5),d2
	move.l	d5,d3
	call	Write
;---------------------------------------------------------
	move.l	File(a5),d1
	lea	Hunk2(pc),a0
	move.l	a0,d2
	move.l	#Hunk3-Hunk2,d3
	call	Write
;---------------------------------------------------------
	move.l	File(a5),d1
	call	Close
;---------------------------------------------------------
	move.l	ExecBase,a6
	move.l	Size(a5),d0
	move.l	Buffer(a5),a1
	call	FreeMem
;---------------------------------------------------------
	move.l	DosBase(a5),a1
	call	CloseLibrary
;---------------------------------------------------------
	movem.l	(sp)+,d0-d7/a0-a6
	rts

**********************************************************
HunkTable:	
;---------------------------------------------------------
Hunk1:	dc.l	999,0	;hunk unit;no name
	dc.l	1002	;hunk data
LongSize:	dc.l	0	;number of longwords
	dc.b	"                        "	;leading spaces
;---------------------------------------------------------
Hunk2:	dc.l	1007	;hunk ext
;---------------------------------------------------------
	dc.b	1,0,0,2	;ext rel def
	dc.b	"BGNTEXT",0
BGNTEXT:	dc.l	0	;begin of text definition
;---------------------------------------------------------
	dc.b	1,0,0,2	;ext rel def
	dc.b	"ENDTEXT",0
ENDTEXT:	dc.l	0	;end of text definition
;---------------------------------------------------------
	dc.b	2,0,0,2	;ext abs def
	dc.b	"HITEXT",0,0
HITEXT:	dc.l	0	;16*number of characters definition
;---------------------------------------------------------
	dc.l	0	;end hunk ext
;---------------------------------------------------------
	dc.l	1010	;hunk end
;---------------------------------------------------------
Hunk3:	
**********************************************************
DosName:	dc.b	"dos.library",0
	even
FileIn:	dc.b	"Source/Text",0
	even
FileOut:	dc.b	"Parts/Text.lnk",0
	even
**********************************************************
	cnop	0,4
DataTable:
	rsset	0

FIB:	rs.b	fib_SIZEOF
File:	rs.l	1
Lock:	rs.l	1
DosBase:	rs.l	1
Size:	rs.l	1
Buffer:	rs.l	1

Data_SIZE:	rs.w	0

	ds.b	Data_SIZE
	
	
	
