 Include "equ.h"
 Include "impequ.h"

TAB	equ	9
CR	equ	$d
LF	equ	$a
FF	equ	$c
ESC	equ	$1b

 SECTION wp,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,wp		;Word Perfect

*
* Word Perfect
*
check:	move.l	table,a0
	move.l	buff1(a0),a1
	move.l	(a1),a1
	cmp.b	#$80,(a1)+
	bne	never
	cmp.b	#$80,(a1)+
	bne	never

	moveq	#2,d0
irts:	rts


***
*** Text File Import
***

*
* Word Perfect
*
wp:	move.l	table,a0
	move.l	f_openr(a0),a0
	jsr	(a0)
	beq	ascii9

	move.l	table,a0
	move.l	t_open(a0),a0
	jsr	(a0)
	beq	ascii9

	clr.w	attrb
	clr.w	lin
	clr.w	rin
	clr.w	bmod

ascii1:	bsr	tget
	beq	ascii9

	lea	commands,a0
ascii2:	move.b	(a0),d1
	beq	ascii3
	cmp.b	d0,d1
	beq	docmd
	addq.l	#6,a0
	bra	ascii2

ascii3:	cmp.b	#$c0,d0
	bcc	skipto
	cmp.b	#$20,d0
	bcs	ascii1
	cmp.b	#$80,d0
	bcc	ascii1

	bsr	tput
	beq	ascii9
	bra	ascii1

skipto:	move.b	d0,temp
skpto1:	bsr	tget
	beq	ascii9
	cmp.b	temp,d0
	bne	skpto1
	bra	ascii1

docmd:	move.l	2(a0),a0
	jmp	(a0)

*
* end of input file.  close and flush buffer
*
ascii9:	move.l	table,a0
	move.l	f_closer(a0),a0
	jsr	(a0)

	move.l	table,a0
	move.l	t_close(a0),a0
	jmp	(a0)

*
*
dospace:
	move.b	#$20,d0
	bsr	tput
	beq	ascii9
	bra	ascii1


docr:	move.w	#CMD_CR,d0
	bsr	tputw
	beq	ascii9
	bra	ascii1


dotab:	move.w	#CMD_TAB,d0
	bsr	tputw
	beq	ascii9
	bra	ascii1

dodash:	move.b	#"-",d0
	bsr	tput
	beq	ascii9
	bra	ascii1

extended:
	bsr	tget
	beq	ascii9
	and.w	#$ff,d0
	lea	ktoi,a0
	move.b	0(a0,d0.w),d0
	beq	extend1
	bsr	tput
extend1:
	bsr	tget
	beq	ascii9
	bra	ascii1

domhyp:
	move.w	#CMD_IMH,d0
	bsr	tputw
	beq	ascii9
	bra	ascii1

superscript:
	add.w	#400,bmod
script:	move.w	#CMD_BMOD,d0
	bsr	tputw
	beq	ascii9
	move.w	bmod,d0
	bsr	tputw
	beq	ascii9
	bra	ascii1


subscript:
	sub.w	#400,bmod
	bra	script


leftj:	move.w	#CMD_JST,d0
	bsr	tputw
	beq	ascii9
	moveq	#0,d0
	move.b	d0,justify
	bsr	tput
	beq	ascii9
	bra	ascii1


centerj:
	move.w	#CMD_JST,d0
	bsr	tputw
	beq	ascii9
	moveq	#1,d0
	bsr	tput
	beq	ascii9

ctrj0:	bsr	tget
	beq	ascii9
	cmp.b	#$c3,d0
	bne	ctrj0
	bra	ascii1

rightj:	move.w	#CMD_JST,d0
	bsr	tputw
	beq	ascii9
	moveq	#2,d0
	bsr	tput
	beq	ascii9

rhtj0:	bsr	tget
	beq	ascii9
	cmp.b	#$c4,d0
	bne	rhtj0


prevj:	move.w	#CMD_JST,d0
	bsr	tputw
	beq	ascii9
	move.b	justify,d0
	bsr	tput
	beq	ascii9
	bra	ascii1


charj:	move.w	#CMD_JST,d0
	bsr	tputw
	beq	ascii9
	moveq	#3,d0
	move.b	d0,justify
	bsr	tput
	beq	ascii9
	bra	ascii1

margin:	bsr	tget
	beq	ascii9
	bsr	tget
	beq	ascii9

	bsr	tget
	beq	ascii9
	and.w	#$ff,d0
	mulu	#720,d0
	move.w	d0,lin
	bsr	tget
	beq	ascii9
	and.w	#$ff,d0
	mulu	#720,d0
	move.w	d0,rin
	bsr	tget
	beq	ascii9
;	cmp.b	#$c0,d0
;	bne	ascii9
;	move.w	#CMD_IN,d0
;	bsr	tputw
;	beq	ascii9
;	move.w	lin,d0
;	bsr	tputw
;	beq	ascii9
;	move.w	rin,d0
;	bsr	tputw
;	beq	ascii9
	bra	ascii1

lindent:
	bsr	tget
	beq	ascii9
	and.w	#$ff,d0
	mulu	#720,d0
	move.w	lin,d1
	sub.w	d0,d1
	bcc	lin1
	moveq	#0,d1
lin1:	move.w	d1,lin

	bsr	tget
	beq	ascii9
	cmp.b	#$c2,d0
	bne	ascii9
	move.w	#CMD_IN,d0
	bsr	tputw
	beq	ascii9
	move.w	lin,d0
	bsr	tputw
	beq	ascii9
	move.w	rin,d0
	bsr	tputw
	beq	ascii9
	bra	ascii1


linespacing:
	bsr	tget
	beq	ascii9
	and.w	#$ff,d0
	mulu	#600,d0
	move.w	d1,lspac

	bsr	tget
	beq	ascii9
	cmp.b	#$c1,d0
	bne	ascii9
	move.w	#CMD_LSP,d0
	bsr	tputw
	beq	ascii9
	move.w	lspac,d0
	sub.w	#1200,d0
	bsr	tputw
	beq	ascii9
	bra	ascii1


tlindent:
	bsr	tget
	beq	ascii9
	and.w	#$ff,d0
	mulu	#600,d0
	move.w	d0,temp
	bsr	tget
	beq	ascii9
	and.w	#$ff,d0
	mulu	#600,d0
	sub.w	temp,d0
	move.w	d0,lin

	bsr	tget
	beq	ascii9
	cmp.b	#$cc,d0
	bne	ascii9
	move.w	#CMD_IN,d0
	bsr	tputw
	beq	ascii9
	move.w	lin,d0
	bsr	tputw
	beq	ascii9
	move.w	rin,d0
	bsr	tputw
	beq	ascii9
	bra	ascii1

tmargin:
	bsr	tget
	beq	ascii9
	bsr	tget
	beq	ascii9
	and.w	#$ff,d0
	mulu	#600,d0
	move.w	d0,lin
	move.w	d0,rin

	bsr	tget
	beq	ascii9
	cmp.b	#$e0,d0
	bne	ascii9
	move.w	#CMD_IN,d0
	bsr	tputw
	beq	ascii9
	move.w	lin,d0
	bsr	tputw
	beq	ascii9
	move.w	rin,d0
	bsr	tputw
	beq	ascii9
	bra	ascii1


trestore:
	bsr	tget
	beq	ascii9
	bsr	tget
	beq	ascii9
	bsr	tget
	beq	ascii9
	cmp.b	#$de,d0
	bne	ascii9
	clr.w	lin
	clr.w	rin

	move.w	#CMD_IN,d0
	bsr	tputw
	beq	ascii9
	move.w	lin,d0
	bsr	tputw
	beq	ascii9
	move.w	rin,d0
	bsr	tputw
	beq	ascii9
	bra	ascii1


doubleon:
	move.w	#DOUBLEU,d0
	bra	a_on

doubleoff:
	move.w	#DOUBLEU,d0
	bra	a_off

strikeon:
	move.w	#STRIKE,d0
	bra	a_on

strikeoff:
	move.w	#STRIKE,d0
	bra	a_off

underon:
	move.w	#UNDER,d0
	bra	a_on

underoff:
	move.w	#UNDER,d0
	bra	a_off

boldon:
	move.w	#BOLD,d0
	bra	a_on

boldoff:
	move.w	#BOLD,d0
	bra	a_off

italicon:
	move.w	#ITALICS,d0
	bra	a_on

italicoff:
	move.w	#ITALICS,d0
	bra	a_off

a_on:	move.w	attrb,d1
	bset	d0,d1
	bne	irts
	move.w	d1,attrb
	move.w	#CMD_AT,d0
	bsr	tputw
	beq	ascii9
	moveq	#0,d0
	move.w	attrb,d0
	bsr	tputl
	beq	ascii9
	bra	ascii1


a_off:	move.w	attrb,d1
	bclr	d0,d1
	beq	irts
	move.w	d1,attrb
	move.w	#CMD_AT,d0
	bsr	tputw
	beq	ascii9
	moveq	#0,d0
	move.w	attrb,d0
	bsr	tputl
	beq	ascii9
	bra	ascii1


tget:	move.l	table,a0
	move.l	f_get(a0),a0
	jmp	(a0)

tput:	move.l	table,a0
	move.l	t_put(a0),a0
	jmp	(a0)

tputw:	move.l	table,a0
	move.l	t_putw(a0),a0
	jmp	(a0)

tputl:	move.l	table,a0
	move.l	t_putl(a0),a0
	jmp	(a0)

*******************************************************************
***	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 wp,DATA,PUBLIC

commands:
	dc.b	LF,0
	dc.l	docr
	dc.b	$8c,0
	dc.l	docr

	dc.b	TAB,0
	dc.l	dotab
	dc.b	CR,0
	dc.l	dospace
	dc.b	$0b,0
	dc.l	dospace
	dc.b	$0c,0
	dc.l	dospace

	dc.b	$a0,0
	dc.l	dospace
	dc.b	$a9,0
	dc.l	dodash
	dc.b	$aa,0
	dc.l	dodash
	dc.b	$ab,0
	dc.l	dodash

	dc.b	$ac,0
	dc.l	domhyp
	dc.b	$ad,0
	dc.l	domhyp
	dc.b	$ae,0
	dc.l	domhyp

	dc.b	$bc,0
	dc.l	superscript
	dc.b	$bd,0
	dc.l	subscript

	dc.b	$81,0
	dc.l	charj
	dc.b	$82,0
	dc.l	leftj
	dc.b	$83,0
	dc.l	prevj
	dc.b	$84,0
	dc.l	prevj
	dc.b	$c3,0
	dc.l	centerj
	dc.b	$c4,0
	dc.l	rightj

	dc.b	$90,0
	dc.l	doubleon
	dc.b	$91,0
	dc.l	doubleoff
	dc.b	$92,0
	dc.l	strikeon
	dc.b	$93,0
	dc.l	strikeoff
	dc.b	$94,0
	dc.l	underon
	dc.b	$95,0
	dc.l	underoff
	dc.b	$9d,0
	dc.l	boldon
	dc.b	$9c,0
	dc.l	boldoff

	dc.b	$b2,0
	dc.l	italicon
	dc.b	$b3,0
	dc.l	italicoff

	dc.b	$c0,0
	dc.l	margin

	dc.b	$cc,0
	dc.l	tlindent
	dc.b	$e0,0
	dc.l	tmargin
	dc.b	$de,0
	dc.l	trestore

	dc.b	$e1,0
	dc.l	extended

	dc.b	0,0

*
*
*

 IF AMIGA
* 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

 ENDIF

 IF ATARIST
* AtariST 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	199,252,233,226,228,224,229,231
	dc.b	234,235,232,239,238,236,196,197
	dc.b	201,230,198,244,246,242,251,249
	dc.b	254,214,220,162,163,161,187,164
	dc.b	225,237,243,250,241,209,189,156
	dc.b	185,000,141,145,144,186,136,137
	dc.b	227,245,159,191,247,215,192,195
	dc.b	213,000,000,180,181,183,184,182
	dc.b	000,000,138,000,000,000,000,000
	dc.b	000,000,000,000,000,000,000,000
	dc.b	000,000,000,000,000,000,000,000
	dc.b	000,000,000,000,000,165,000,151
	dc.b	000,000,000,150,000,000,153,000
	dc.b	000,000,000,000,000,160,000,000
	dc.b	131,140,135,134,000,000,139,130
	dc.b	155,172,171,128,147,148,149,173
 ENDIF

*
special:
	dc.w	1
	dc.l	spcl1
*
name:	dc.b	"Word Perfect v2.0.3",0
spcl1:	dc.b	"Formated Text",0

 SECTION wp,BSS,PUBLIC
temp:		ds.l	1
lin:		ds.w	1
rin:		ds.w	1
lspac:		ds.w	1
bmod:		ds.w	1
justify:	ds.b	1
		ds.b	1
attrb:		ds.w	1
