
		CASE	OBJECT 

CORRECT		RECORD 0

UCHAR		DS.L 1
co_qthresh	DS.W 1
co_rankf	DS.W 1
co_rcount	DS.W 1
co_minrank	DS.W 1

			ENDR

;-----------------------------------------------
;
;   Imported addresses
;
;-----------------------------------------------

	IMPORT	Coplex
	IMPORT	Convplex
	IMPORT	Cophlen
	IMPORT	Cophquery
	IMPORT	Coqfull
	IMPORT	Coqnvplex
	IMPORT	Coqphlen
	IMPORT	Coqplex
	IMPORT	Corinfo:CORRECT
	IMPORT	Engphtab
	IMPORT	Scfdecomp
	IMPORT	corrform
	IMPORT	qtheta
	IMPORT	rankalt
	IMPORT	theta
	
	
;Cominrank	equ Corinfo.co_minrank
;Coqthresh	equ Corinfo.co_qthresh

*****************************************************************
*
*   CORASM.SRC - Various routines from corrphon.c I hand-coded
*
*   Robert A. Hearn
*
*****************************************************************

	LOAD 'macros.dump'
	
	
	
*****************************************************************

rankword	PROC		EXPORT

E_LRIND	equ 4
FLAGSIND	equ $ff
IW_COMMON	equ 1
IW_TAG	equ $80
NPHON	equ 58
IW_SPECIAL	equ $10
E_FILL	equ $0b
E_FILL2	equ $0b0b
E_LOPELEN	equ 6
E_HIPELEN	equ 6
E_LOPLEX	equ 2
E_HIPLEX	equ 2
E_LONVPLEX	equ 1
E_HINVPLEX	equ 1
E_LOLEN	equ 6
E_HILEN	equ 6
E_REPEAT	equ $09



		input word:l,expword:l,fullw:l
		local t1:w,t2:w,wordptr:l,expptr:l,flen:w,simil:w
		local tptr:l

		begin

		movelong expword,expptr
		movelong word,wordptr
		movelong #Engphtab,tptr

loop1	lda [wordptr]
		inc wordptr
		and #$ff
		bne trylrind
		moveword #0,[expptr]
		bra break

trylrind	cmp #E_LRIND
		bne notlrind

		moveword #0,[expptr]
		lda Scfdecomp
		and #IW_SPECIAL
		bne special
		bra break
special	movelong expword,expptr
loop2	lda [expptr]
		tax
		and #$ff
		beq break
		txa
		cmp #E_FILL2
		bne next2
		shortm
		moveword [wordptr],[expptr]
		longm
next2	inc wordptr
		inc expptr
		inc expptr
		bra loop2

notlrind	asl a
		tay
		moveword [tptr]:y,[expptr]
		inc expptr
		inc expptr
		brl loop1

break	eval 'expptr.-expword'
		tax
		eval '.-Cophlen'
		bmi neg1
		cmp #E_HIPELEN
		jgt done
		bra ok1
neg1	eval '.+#E_LOPELEN'
		jmi done

ok1	pha
		pushlong Cophquery
		pushlong expword
		pushword Cophlen
		phx
		jsl qtheta
		pla
		cmp Corinfo.co_qthresh
		jmi done

		pushlong fullw
		pushlong expword
		jsl corrform
		ply
		ply
		ply
		ply
		sta flen

		eval 'Coplex.-Coqplex'
		bmi neg2
		cmp #E_HIPLEX
		jgt done
		bra ok2
neg2	eval '.+#E_LOPLEX'
		jmi done

ok2	eval 'Convplex.-Coqnvplex'
		bmi neg3
		cmp #E_HINVPLEX
		jgt done
		bra ok3
neg3	eval '.+#E_LONVPLEX'
		jmi done

ok3	eval 'flen.-Coqphlen'
		bmi neg4
		cmp #E_HILEN
		jgt done
		bra ok4
neg4	eval '.+#E_LOLEN'
		jmi done

ok4	call theta,in=(Coqfull:l,fullw:l,Coqphlen:w,flen:w),out=simil:w
		cmpw simil,Corinfo.co_minrank
		jlt done

		movelong expword,expptr
		movelong word,wordptr
loop3	lda [wordptr]
		inc wordptr
		and #$ff
		bne not0
		moveword #0,[expptr]
		movelong expword,wordptr
		bra break2
not0	cmp #E_LRIND
		beq break2

default	asl a
		tay
		lda [tptr],y
		and #$ff
		cmp #E_REPEAT
		bne notrepeat
		dec expptr
		lda [expptr]
		inc expptr
		sta [expptr]
		inc expptr
		bra loop3
notrepeat	cmp #E_FILL
		beq loop3
default2	sta [expptr]
		inc expptr
		bra loop3

break2	movelong #Scfdecomp,expptr

loop4	cmpw simil,Corinfo.co_minrank
		ble done
		lda [expptr]
		inc expptr
		and #$ff
		beq done
		pha
		pushword simil
		pushlong wordptr
		jsl rankalt
		ply
		ply
		ply
		ply
		bra loop4

done	return

		ENDP
		END

