.PAGE
;******************************************************
;*						      *
;*		  Disassembler Routines		      *
;*						      *
;*  COPYRIGHT (c) 1982, 1983 SAGE Computer Technology *
;*  All Rights Reserved				      *
;*						      *
;******************************************************
;Print arithmetic instructions

;			D7 : Instruction
;	BRA	ARITHLOC
;			D7 : Instruction

ARITHLOC
	MOVE.W	D7,D5		;Set instruction size
	LEA	ARITHINS,A1
	BSR.S	INSSIZEP	;Print instruction and size
	BTST	#8,D7		;Which direction
	BEQ.S	$1		;EA .op. Dn -> Dn
	BSR.S	$10		;print register
	BSR	TERMCOMA	;Print delimier
$5
	BSR	QPRTEADD	;Print effective address
	RTS
$1
	BSR.S	$5		;Print effective address
	BSR	TERMCOMA	;Print delimiter
$10
	MOVE.W	D7,D3		;Calc register number
	ROR.W	#6,D3
	BSR	DRD		;Print Data register direct
	RTS
	
;Print instruction

;	BSR	INSSIZEP

INSSIZEP
	MOVE.W	D7,D1		;Print instruction type
	ROL.W	#4,D1		;Calculate numonic
	ANDI.W	#07H,D1
	BSR	PRTINST
	TST.W	D5		;Size to be printed
	BEQ.S	$1
	BSR	PRTOSIZE	;Print instruction size
$1
	BSR	NXTFIELD	;Move to operand field
	RTS

;Print decimal and extend instructions

;		D7 : Instruction
;	BSR	DEC - Decimal instruction
;	BSR	EXTEND - Extend instructions
;		D7 : Instruction

DEC
	CLR.L	D5		;Dont print size
	BRA.S	EXTEND1		;Process command
EXTEND
	MOVE.W	D7,D5		;Print instruction size
EXTEND1
	LEA	DECINS,A1
	BSR	INSSIZEP	;Print instruction and size if needed
	MOVE.W	D7,D3		;Print source register
	ROL.W	#3,D3		;Position register
	BSR.S	$2		;Print register
	BSR	TERMCOMA	;Print delimiter
	MOVE.W	D7,D3
	ROR.W	#6,D3		;Print destination register
$2
	BTST	#3,D7		;Register to register or memory to memory
	BNE.S	$1		;Memory to Memory
	BSR	DRD		;Print Data register direct
	RTS
$1
	BSR	ARIPD		;Print Address register with predecrement
	RTS

;1000 - OR/DIV/SBCD

ODSI
	MOVE.W	D7,D0		;Calculate instruction type
	ANDI.W	#1F0H,D0	;SBCD?
	CMPI.W	#100H,D0
	BEQ	DEC		;Yes - Process SCBD
	LSR.W	#6,D0		;DIVU or DIVS
	MOVEQ	#4,D1		;Assume DIVU
	SUBQ.W	#3,D0		;DIVU
	BEQ.S	DIVMUL		;Yes
	SUBQ.W	#4,D0		;DIVS
	BNE	ARITHLOC	;OR instruction - Process it
	MOVEQ	#5,D1		;Set DIVS instruction
DIVMUL
	BCLR	#6,D7		;Convert to Data register reference
	OR.W	#4100H,D7
	BRA	M906

;1001 - SUB/SUBX - See process 1101

;1011 - CMP/EOR

CMPEOR
	MOVE.W	D7,D0		;CMP instruction?
	ROR.W	#6,D0
	ANDI.W	#7,D0
	SUBQ.W	#2,D0
	BLE	ARITHLOC	;Yes - process it
	LEA	DECINS,A1	;Use decimal intruction
	MOVEQ	#40H,D5		;Assume CMPA.W
	SUBQ.W	#1,D0		;CMP.W ?
	BEQ.S	$1		;Yes process it
	ROL.W	#1,D5		;Convert to word
	SUBQ.W	#4,D0		;CMPA.L
	BNE.S	$2		;No
$1
	BSR	INSSIZEP	;Print instruction & size
	BSR	QPRTEADD	;Print effective address
	BSR	TERMCOMA	;Print delimiter
	MOVE.W	D7,D3		;Print Address register
	ROR.W	#6,D3
	BSR	ARD
	RTS
$2
	SUBI.W	#1000H,D7	;Convert EOR
	MOVE.W	D7,D0		;CMPM or EOR?
	ANDI.W	#38H,D0
	CMPI.W	#08H,D0
	BNE	ARITHLOC	;EOR
	MOVE.L	FCMPM,D0
	BSR	PRTRINST
	MOVE.W	D7,D5		;Set instruction size
	BSR	PRTOSIZE	;Print instruction size
	BSR	NXTFIELD
	MOVE.W	D7,D3		;Print source
	ROL.W	#3,D3
	BSR.S	$3
	BSR	TERMCOMA	;Print delimiter
	MOVE.W	D7,D3		;Print destination register
	ROR.W	#6,D3
$3
	BSR	ARIPI		;Print register with predecrement
	RTS
	
;1100 - AND/MUL/ABCD/EXG

AMAEI
	MOVE.W	D7,D0		;Decode instruction
	ANDI.W	#1F8H,D0
	MOVEQ	#0,D4		;Assume Dn,Dn
	CMPI.W	#140H,D0	;EXG Dn,Dn?
	BEQ.S	$1		;Yes process it
	MOVEQ	#3,D4		;Assume An,An
	CMPI.W	#148H,D0	;EXG An,An
	BEQ.S	$1		;Yes process it
	MOVEQ	#2,D4		;Assume Dn,An
	CMPI.W	#188H,D0	;EXG Dn,An
	BNE.S	$3		;No try next possibility
$1
	MOVE.L	FEXG,D0		;Print instruction
	BSR	PRTRINST
	BSR	NXTFIELD	;Move to next field
	MOVE.W	D7,D3		;Print source address
	ROR.W	#6,D3
	BSR.S	$2		;Print source
	BSR	TERMCOMA	;Print delimiter
	MOVE.W	D7,D3		;Print destination register
	ROL.W	#3,D3
$2
	ROR.B	#1,D4		;Print A register or D register
	BCS	ARD		;Print A register
	BRA	DRD		;Print D register
$3
	LSR.W	#4,D0		;ABCD?
	CMPI.B	#10H,D0
	BEQ	DEC		;Print it
	MOVEQ	#6,D1		;Set to MULU instruction
	LSR.W	#2,D0		;MULU or MULS
	SUBQ.W	#3,D0		;MULU instruction
$4
	BEQ	DIVMUL		;Yes process it
	MOVEQ	#7,D1		;Assume	 MULS instruction
	SUBQ.W	#4,D0		;MULS instruction?
	BEQ	$4		;Yes process it
	BRA	ARITHLOC	;None of the above must be AND

;1001 - SUB/SUBX - See process 1101
;1101 - ADD/ADDX

SUBS
ADDS
	MOVE.W	D7,D0		;ADD or ADDX instruction
	ANDI.W	#0C0H,D0	;ADDA or SUBA
	CMPI.W	#0C0H,D0
	BEQ.S	$1
	MOVE.W	D7,D0
	ANDI.W	#130H,D0
	CMPI.W	#100H,D0	;ADDX instruction?
	BEQ	EXTEND		;Yes - process ADDX
	BRA	ARITHLOC	;Must be ADD process it
$1
	MOVE.W	D7,D5		;Set instruction size
	ROR.W	#1,D5
	LEA	ARITHTOA,A1
	MOVE.W	D7,D1		;Calc instuction
	ROL.W	#2,D1
	ANDI.W	#1,D1
	BSR	PRTINST		;Print instruction and size
	BSR	PRTSIZE
	BSR	NXTFIELD
	BSR	QPRTEADD	;Print effective address
	BSR	TERMCOMA	;Print delimiter
	MOVE.W	D7,D3		;Calc register number
	ROR.W	#6,D3
	BSR	ARD		;Print Address register direct
	RTS

;1110 - Shift/Rotate

SHFROT
	MOVE.W	D7,D1		;Print instruction
	MOVE.W	D7,D5		;Memory or Register shift
	ANDI.W	#0C0H,D5
	CMPI.W	#0C0H,D5
	BEQ.S	$10		;Memory shift
	ROR.W	#3,D1		;Position type in lower two bits
	BSR.S	$100		;Print instruction
	BSR	PRTOSIZE	;Print shift size
	BSR	NXTFIELD	;Move to operand field
	MOVE.W	D7,D3		;Setup for shift count print
	ANDI.W	#0E00H,D3
	BTST	#5,D7		;Imediate or Register count
	BEQ.S	$1		;Imediate
	ROR.W	#6,D3
	BSR	DRD		;Print count register
	BRA.S	$2
$1
	MOVEQ	#"#",D0		;Print constant designator
	BSR	TERMCHAR
	MOVE.W	D3,D0		;Print shift count
	ROL.W	#7,D0
	ANDI.B	#0FH,D0
	BNE.S	$15		;0 => 8
	MOVEQ	#8,D0
$15
	BSR	TERMDIGT
$2
	BSR	TERMCOMA	;Print delimiter
	MOVE.W	D7,D3		;Print register
	ROL.W	#3,D3
	BSR	DRD
	RTS
$10
	ROL.W	#7,D1		;Shift type into proper position
	BSR.S	$100		;Print instruction
	CLR.L	D5		;Use byte if illegal
	BSR	NXTFIELD	;Move to operand field
	BSR	QPRTEADD	;Print effective address
	RTS
	
$100
	ANDI.W	#3,D1		;Use only lower 2 bits
	MOVE.W	D7,D2		;Add direction indicator
	ANDI.W	#100H,D2	; and only dirction indicator
	ROR.W	#6,D2		;Position direction indicator
	OR.W	D2,D1
	LEA	SHFINS,A1	;Print instruction
	BSR	PRTINST
	RTS
	
	
;1010 & 1111 - (Unassigned)

IERROR
	MOVEQ	#".",D0		;Print .WORD
	BSR	PRTRINST
	MOVE.L	FWORD,D0
	BSR	PRTRINST
	BSR	NXTFIELD
	MOVE.W	D7,D0		;Print data value of illegal instruction
	BSR	TERMHEXW	;Print illegal instruction
	RTS

                                                            