/*
DISAM68K.c
Copyright (C) 2010 Paul C. Pratt
You can redistribute this file and/or modify it under the terms
of version 2 of the GNU General Public License as published by
the Free Software Foundation. You should have received a copy
of the license along with this file; see the file COPYING.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
license for more details.
*//*
DISAssemble Motorola 68K instructions.
*/#ifndef AllFiles#include"SYSDEPNS.h"#include"ENDIANAC.h"#include"MYOSGLUE.h"#include"EMCONFIG.h"#include"GLOBGLUE.h"#include"M68KITAB.h"#endif#include"DISAM68K.h"LOCALVARui5rDisasm_pc;/*
don't use get_vm_byte/get_vm_word/get_vm_long
so as to be sure of no side effects
(if pc points to memory mapped device)
*/LOCALVARui3pDisasm_pcp;LOCALVARui5rDisasm_pc_blockmask;LOCALVARui3bDisasm_pcp_dummy[2]={0,0};IMPORTFUNCATTepFindATTel(CPTRaddr);LOCALPROCDisasm_Find_pcp(void){ATTepp;p=FindATTel(Disasm_pc);if(0==(p->Access&kATTA_readreadymask)){Disasm_pcp=Disasm_pcp_dummy;Disasm_pc_blockmask=0;}else{Disasm_pc_blockmask=p->usemask&~p->cmpmask;Disasm_pc_blockmask=Disasm_pc_blockmask&~(Disasm_pc_blockmask+1);Disasm_pcp=p->usebase+(Disasm_pc&p->usemask);}}LOCALFUNCui4rDisasm_nextiword(void)/* NOT sign extended */{ui4rr=do_get_mem_word(Disasm_pcp);Disasm_pcp+=2;Disasm_pc+=2;if(0==(Disasm_pc_blockmask&Disasm_pc)){Disasm_Find_pcp();}returnr;}LOCALINLINEFUNCui3rDisasm_nextibyte(void){return(ui3b)Disasm_nextiword();}LOCALFUNCui5rDisasm_nextilong(void){ui5rhi=Disasm_nextiword();ui5rlo=Disasm_nextiword();ui5rr=((hi<<16)&0xFFFF0000)|(lo&0x0000FFFF);returnr;}LOCALPROCDisasm_setpc(CPTRnewpc){if(newpc!=Disasm_pc){Disasm_pc=newpc;Disasm_Find_pcp();}}LOCALVARui5bDisasm_opcode;LOCALVARui5bDisasm_opsize;#define Disasm_b76 ((Disasm_opcode >> 6) & 3)#define Disasm_b8 ((Disasm_opcode >> 8) & 1)#define Disasm_mode ((Disasm_opcode >> 3) & 7)#define Disasm_reg (Disasm_opcode & 7)#define Disasm_md6 ((Disasm_opcode >> 6) & 7)#define Disasm_rg9 ((Disasm_opcode >> 9) & 7)LOCALPROCDisasmOpSizeFromb76(void){Disasm_opsize=1<<Disasm_b76;switch(Disasm_opsize){case1:dbglog_writeCStr(".B");break;case2:dbglog_writeCStr(".W");break;case4:dbglog_writeCStr(".L");break;}}LOCALPROCDisasmModeRegister(ui5bthemode,ui5bthereg){switch(themode){case0:dbglog_writeCStr("D");dbglog_writeHex(thereg);break;case1:dbglog_writeCStr("A");dbglog_writeHex(thereg);break;case2:dbglog_writeCStr("(A");dbglog_writeHex(thereg);dbglog_writeCStr(")");break;case3:dbglog_writeCStr("(A");dbglog_writeHex(thereg);dbglog_writeCStr(")+");break;case4:dbglog_writeCStr("-(A");dbglog_writeHex(thereg);dbglog_writeCStr(")");break;case5:dbglog_writeHex(Disasm_nextiword());dbglog_writeCStr("(A");dbglog_writeHex(thereg);dbglog_writeCStr(")");break;case6:dbglog_writeCStr("???");#if 0 ArgKind = AKMemory;
ArgAddr.mem = get_disp_ea(m68k_areg(thereg));
#endif
break;case7:switch(thereg){case0:dbglog_writeCStr("(");dbglog_writeHex(Disasm_nextiword());dbglog_writeCStr(")");break;case1:dbglog_writeCStr("(");dbglog_writeHex(Disasm_nextilong());dbglog_writeCStr(")");break;case2:{ui5rs=Disasm_pc;s+=ui5r_FromSWord(Disasm_nextiword());dbglog_writeCStr("(");dbglog_writeHex(s);dbglog_writeCStr(")");}break;case3:dbglog_writeCStr("???");#if 0 ArgKind = AKMemory;
s = get_disp_ea(Disasm_pc);
#endif
break;case4:dbglog_writeCStr("#");if(Disasm_opsize==2)