 Include "equ.h"
 Include "impequ.h"

 SECTION ftxt,CODE,PUBLIC
***************************************************
***						***
***************************************************
dumbentry:
	clr.l	d0
	rts

	dc.l	"IMPT"
	dc.w	200
	dc.l	0

table:	dc.l	0
	dc.l	name,special,check,ftxt

*
* Excellence Check routine
*
check:	move.l	table,a0
	move.l	buff1(a0),a1
	move.l	(a1),a1
	cmp.l	#"FORM",(a1)
	bne	never
	cmp.l	#"FTXT",8(a1)
	bne	never
	moveq	#2,d0
rrts:	rts


***
*** Text File Import
***

*
* Excellence
*
ftxt:	move.l	sp,savesp

	move.l	table,a0
	move.l	f_openr(a0),a0
	jsr	(a0)
	beq	rrts

	move.l	table,a0
	move.l	t_open(a0),a0
	jsr	(a0)
	beq	ftxt9

	jsr	pgetl		;"FORM"
	jsr	pgetl
	move.l	d0,length
	jsr	pgetl		;"FTXT"
	sub.l	#4,length

	clr.b	prevstyle
	clr.b	curstyle
	move.l	#1200,curpoint

getchunk:
	jsr	pgetl
	move.l	d0,temp
	jsr	pgetl
	move.l	d0,clength
	sub.l	#8,length

	move.l	temp,d0
	lea	chunks,a0
gc1:	tst.l	(a0)
	beq	gc2
	cmp.l	(a0),d0
	beq	gc2
	lea	8(a0),a0
	bra	gc1

gc2:	move.l	4(a0),a0
	jsr	(a0)
	tst.l	length
	bne	getchunk

ftxt9:	move.l	table,a0
	move.l	f_closer(a0),a0
	jsr	(a0)
	move.l	table,a0
	move.l	t_close(a0),a0
	jmp	(a0)


***********************************
***				***
***********************************
chrs:	move.l	clength,temp
chrs1:	jsr	pget
	cmp.b	#$a,d0
	beq	chrcr
	lea	ktoi,a0
	and.w	#$ff,d0
	move.b	0(a0,d0.w),d0
	beq	chrs2
	jsr	tput
	bra	chrs2
chrcr:	move.w	#CMD_CR,d0
	jsr	tputw
chrs2:	subq.l	#1,temp
	bne	chrs1
	bra	adjlen

***********************************
***				***
***********************************
fons:	jsr	pget
	jsr	pget
	and.w	#$ff,d0
	mulu	#100,d0
	move.l	d0,curpoint
	move.w	#CMD_PT,d0
	jsr	tputw
	move.l	curpoint,d0
	btst	#3,curstyle
	beq	fons0
	lsl.l	#1,d0
fons0:	jsr	tputl
	move.l	curpoint,d0
	jsr	tputl

	move.l	clength,d0
	add.l	#1,d0
	bclr	#0,d0
	sub.l	d0,length
	subq.l	#2,d0
fons1:	move.l	d0,-(sp)
	jsr	pgetw
	move.l	(sp)+,d0
	sub.l	#2,d0
	bgt	fons1
	rts


***********************************
***				***
***********************************
rule:	bsr	pgetw
	lea	justtbl,a0
	move.b	0(a0,d0.w),d0
	move.w	d0,-(sp)
	move.w	#CMD_JST,d0
	bsr	tputw
	move.w	(sp)+,d0
	bsr	tput

	move.w	#CMD_LSP,d0
	bsr	tputw
	bsr	pgetw
	mulu	#100,d0
	or.w	#$0000,d0
	bsr	tputw


	move.l	clength,d0
	add.l	#1,d0
	bclr	#0,d0
	sub.l	d0,length
	subq.l	#4,d0
rule1:	move.l	d0,-(sp)
	jsr	pgetw
	move.l	(sp)+,d0
	sub.l	#2,d0
	bgt	rule1
	rts


***********************************
***				***
***********************************
styl:	jsr	pget
	move.b	curstyle,d1
	move.b	d1,prevstyle
	move.b	d0,curstyle
	eor.b	d0,d1
	and.b	#%11000111,d1
	beq	nonewa

	moveq	#0,d1
	btst	#0,d0
	beq	newa1
	bset	#BOLD,d1
newa1:	btst	#1,d0
	beq	newa2
	bset	#ITALICS,d1
newa2:	btst	#2,d0
	beq	newa3
	bset	#UNDER,d1
newa3:	btst	#6,d0
	beq	newa4
	bset	#OUTLINE,d1
newa4:	btst	#7,d0
	beq	newa5
	bset	#SHADOW,d1
newa5:	move.l	d1,-(sp)
	move.w	#CMD_AT,d0
	jsr	tputw
	move.l	(sp)+,d0
	jsr	tputl

nonewa:	move.b	prevstyle,d1
	move.b	curstyle,d0
	eor.b	d0,d1
	and.b	#%00110000,d1
	beq	nonewb

	moveq	#0,d1
	btst	#4,d0
	beq	newb1
	move.l	curpoint,d1
	lsr.l	#1,d1
newb1:	btst	#5,d0
	beq	newb2
	move.l	curpoint,d1
	lsr.l	#1,d1
	neg.l	d1
newb2:	move.l	d1,-(sp)
	move.w	#CMD_BMOD,d0
	jsr	tputw
	move.l	(sp)+,d0
	jsr	tputw

nonewb:	move.b	prevstyle,d1
	move.b	curstyle,d0
	eor.b	d0,d1
	and.b	#%00001000,d1
	beq	nonewe

	move.l	curpoint,d1
	btst	#3,d0
	beq	newe1
	lsl.l	#1,d1
newe1:	move.l	d1,-(sp)
	move.w	#CMD_PT,d0
	jsr	tputw
	move.l	(sp)+,d0
	jsr	tputl
	move.l	curpoint,d0
	jsr	tputl

nonewe:	bra	adjlen

***********************************
***				***
***********************************
color:	move.w	#CMD_CFC,d0
	jsr	tputw
	jsr	pget
	cmp.b	#0,d0
	beq	color1
	moveq	#1,d0
color1:	jsr	tput
	bra	adjlen

***********************************
***				***
***********************************
othr:	move.l	clength,d0
othr1:	move.l	d0,-(sp)
	jsr	pget
	cmp.b	#9,d0
	bne	notab
	move.w	#CMD_TAB,d0
	jsr	tputw
notab:	move.l	(sp)+,d0
	subq.l	#1,d0
	bhi	othr1
	bra	adjlen

***********************************
***				***
***********************************
adjlen:	move.l	clength,d0
	btst	#0,d0
	beq	al1
	jsr	pget
	move.l	clength,d0
	add.l	#1,d0

al1:	sub.l	d0,length
	rts


***********************************
***				***
***********************************
skip:	move.l	clength,d0
	add.l	#1,d0
	bclr	#0,d0
	sub.l	d0,length

sk1:	move.l	d0,-(sp)
	jsr	pgetw
	move.l	(sp)+,d0
	sub.l	#2,d0
	bhi	sk1
	rts


***********************************
***				***
***********************************
errrts:	move.l	savesp,sp

	move.l	table,a0
	move.l	f_closer(a0),a0
	jsr	(a0)

	move.l	table,a0
	move.l	t_close(a0),a0
	jmp	(a0)


***********************************
***				***
***********************************
pgetl:	move.l	table,a0
	move.l	f_getl(a0),a0
	jsr	(a0)
	beq	errrts
	rts

pgetw:	move.l	table,a0
	move.l	f_getw(a0),a0
	jsr	(a0)
	beq	errrts
	rts

pget:	move.l	table,a0
	move.l	f_get(a0),a0
	jsr	(a0)
	beq	errrts
	rts

tputw:	move.l	table,a0
	move.l	t_putw(a0),a0
	jsr	(a0)
	beq	errrts
	rts

tputl:	move.l	table,a0
	move.l	t_putl(a0),a0
	jsr	(a0)
	beq	errrts
	rts

tput:	move.l	table,a0
	move.l	t_put(a0),a0
	jsr	(a0)
	beq	errrts
	rts

*******************************************************************
***	called when the import routine choosen finds something	***
***	wrong with the file loaded.				***
*******************************************************************
notright:
	rts

never:	moveq	#0,d0
	rts

maybe:	moveq	#1,d0
	rts

right:	moveq	#2,d0
	rts

***********************************************************
***							***
***********************************************************
 SECTION ftxt,DATA,PUBLIC

chunks:	dc.l	"CHRS",chrs
	dc.l	"FONS",fons
	dc.l	"RULE",rule
	dc.l	"STYL",styl
	dc.l	"CLR ",color
	dc.l	"OTHR",othr
	dc.l	0,skip

justtbl:	dc.b	0,3,1,2

special:
	dc.w	1
	dc.l	spcl1
*
name:	dc.b	"Excellence! v2.0.2",0
*
spcl1:	dc.b	"Formatted Text",0
*

* AMIGA ktoi
ktoi:	dc.b	$00,$00,$00,$00,$00,$00,$00,$00		;$00-$07
	dc.b	$00,$00,$00,$00,$00,$00,$00,$00		;$08-$0f
	dc.b	$00,$00,$00,$00,$00,$00,$00,$00		;$10-$17
	dc.b	$00,$00,$00,$00,$00,$00,$00,$00		;$18-$1f
	dc.b	$20,$21,$22,$23,$24,$25,$26,$27
	dc.b	$28,$29,$2a,$2b,$2c,$2d,$2e,$2f
	dc.b	$30,$31,$32,$33,$34,$35,$36,$37
	dc.b	$38,$39,$3a,$3b,$3c,$3d,$3e,$3f
	dc.b	$40,$41,$42,$43,$44,$45,$46,$47
	dc.b	$48,$49,$4a,$4b,$4c,$4d,$4e,$4f
	dc.b	$50,$51,$52,$53,$54,$55,$56,$57
	dc.b	$58,$59,$5a,$5b,$5c,$5d,$5e,$5f
	dc.b	$60,$61,$62,$63,$64,$65,$66,$67
	dc.b	$68,$69,$6a,$6b,$6c,$6d,$6e,$6f
	dc.b	$70,$71,$72,$73,$74,$75,$76,$77
	dc.b	$78,$79,$7a,$7b,$7c,$7d,$7e,$00

	dc.b	000,000,000,000,000,000,000,000		;$80
	dc.b	000,000,000,000,000,000,000,000		;$88
	dc.b	000,000,000,000,000,000,000,000		;$90
	dc.b	000,000,000,000,000,000,000,000		;$98
	dc.b	000,186,162,163,160,161,142,165		;$a0
	dc.b	000,183,188,136,141,173,184,129		;$a8
	dc.b	155,140,148,149,166,153,181,172		;$b0
	dc.b	000,147,156,137,144,145,146,185		;$b8
	dc.b	192,193,194,195,196,197,198,199		;$c0
	dc.b	200,201,202,203,204,205,206,207		;$c8
	dc.b	157,209,210,211,212,213,214,138		;$d0
	dc.b	159,217,218,219,220,221,158,187		;$d8
	dc.b	224,225,226,227,228,229,230,231		;$e0
	dc.b	232,233,234,235,236,237,238,239		;$e8
	dc.b	189,241,242,243,244,245,246,139		;$f0
	dc.b	191,249,250,251,252,253,190,254		;$f8

*

 SECTION ftxt,BSS,PUBLIC
savesp:		ds.l	1
clength:	ds.l	1
length:		ds.l	1
temp:		ds.l	1

curpoint:	ds.l	1
curstyle:	ds.b	1
prevstyle:	ds.b	1

