From: notaz Date: Sun, 5 Oct 2014 21:17:25 +0000 (+0300) Subject: make Ea* functions easier to work with X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=65044ba9d2f08fbeeb1bd2a4d7c0fb349ea99070;p=cyclone68000.git make Ea* functions easier to work with no functional changes --- diff --git a/Ea.cpp b/Ea.cpp index a67f675..effd4c2 100644 --- a/Ea.cpp +++ b/Ea.cpp @@ -138,7 +138,7 @@ static int EaCalcReg(int r,int ea,int mask,int forceor,int shift,int noshift=0) // If ea>=0x10, trashes r0,r2 and r3, else nothing // size values 0, 1, 2 ~ byte, word, long // mask shows usable bits in r8 -int EaCalc(int a,int mask,int ea,int size,int top,int sign_extend) +int EaCalc(int a,int mask,int ea,int size,EaRWType type) { char text[32]=""; @@ -146,8 +146,9 @@ int EaCalc(int a,int mask,int ea,int size,int top,int sign_extend) if (ea<0x10) { + // Saves one opcode as we can shift in ldr/str int noshift=0; - if (size>=2||(size==0&&(top||!sign_extend))) noshift=1; // Saves one opcode + if (size >= 2 || (size == 0 && type != earwt_sign_extend)) noshift=1; ot(";@ EaCalc : Get register index into r%d:\n",a); @@ -300,19 +301,21 @@ int EaCalc(int a,int mask,int ea,int size,int top,int sign_extend) // --------------------------------------------------------------------------- // Read effective address in (ARM Register 'a') to ARM register 'v' // 'a' and 'v' can be anything but 0 is generally best (for both) -// If (ea<0x10) nothing is trashed, else r0-r3 is trashed -// If 'top' is given, the ARM register v shifted to the top, e.g. 0xc000 -> 0xc0000000 -// If top is 0 and sign_extend is not, then ARM register v is sign extended, -// e.g. 0xc000 -> 0xffffc000 (else it may or may not be sign extended) - -int EaRead(int a,int v,int ea,int size,int mask,int top,int sign_extend,int set_nz) +// If (ea<0x10) nothing is trashed, else r0-r3,r12 is trashed +int EaRead(int a,int v,int ea,int size,int mask,EaRWType type,int set_nz) { char text[32]=""; const char *s=""; int flags_set=0; int shift=0; - if (set_nz) s="s"; + if (set_nz) { + if (type == earwt_msb_dont_care || type == earwt_zero_extend) { + fprintf(stderr, "set_nz on msb_dont_care/zero_extend?\n"); + exit(1); + } + s="s"; + } shift=32-(8<=2||(size==0&&(top||!sign_extend))) { - if(mask) + if (size >= 2 || (size == 0 && type != earwt_sign_extend)) { + if (mask) for (i=mask|0x8000; (i&1)==0; i>>=1) low++; // Find out how high up the EA mask is lsl=2-low; // Having a lsl #2 here saves one opcode } - if (top||!sign_extend) nsarm=3; + if (type == earwt_shifted_up || type == earwt_msb_dont_care) + // use plain ldr + nsarm = 3; ot(";@ EaRead : Read register[r%d] into r%d:\n",a,v); @@ -335,8 +340,10 @@ int EaRead(int a,int v,int ea,int size,int mask,int top,int sign_extend,int set_ else if (lsl<0) ot(" ldr%s r%d,[r7,r%d,lsr #%i]\n",Narm[nsarm],v,a,-lsl); else ot(" ldr%s r%d,[r7,r%d]\n",Sarm[nsarm],v,a); - if (top&&shift) ot(" mov%s r%d,r%d,asl #%d\n",s,v,v,shift); - else if(set_nz) ot(" tst r%d,r%d\n",v,v); + if (type == earwt_shifted_up && shift) + ot(" mov%s r%d,r%d,asl #%d\n",s,v,v,shift); + else if (set_nz) + ot(" tst r%d,r%d\n",v,v); ot("\n"); return 0; } @@ -347,7 +354,7 @@ int EaRead(int a,int v,int ea,int size,int mask,int top,int sign_extend,int set_ { int asl=0; - if (top) asl=shift; + if (type == earwt_shifted_up) asl = shift; if (asl) ot(" mov%s r%d,r%d,asl #%d\n",s,v,a,asl); else if (v!=a) ot(" mov%s r%d,r%d\n",s,v,a); @@ -361,16 +368,12 @@ int EaRead(int a,int v,int ea,int size,int mask,int top,int sign_extend,int set_ // defaults to 1, as most things begins with a read earead_check_addrerr=1; - if (sign_extend) + if (type == earwt_sign_extend) { int d_reg=0; if (shift) { - ot(" mov%s r%d,r%d,asl #%d\n",s,v,d_reg,shift); - d_reg=v; - flags_set=1; - } - if (!top && shift) { - ot(" mov%s r%d,r%d,asr #%d\n",s,v,d_reg,shift); + ot(" mov r%d,r%d,asl #%d\n",v,d_reg,shift); + ot(" mov%s r%d,r%d,asr #%d\n",s,v,v,shift); d_reg=v; flags_set=1; } @@ -381,7 +384,7 @@ int EaRead(int a,int v,int ea,int size,int mask,int top,int sign_extend,int set_ } else { - if (top && shift) { + if (type == earwt_shifted_up && shift) { ot(" mov%s r%d,r0,asl #%d\n",s,v,shift); flags_set=1; } @@ -403,15 +406,14 @@ int EaRead(int a,int v,int ea,int size,int mask,int top,int sign_extend,int set_ // else r0-r3 are trashed // size values 0, 1, 2 ~ byte, word, long // r_ea is reg to store ea in (-1 means ea is not needed), r is dst reg -// if sign_extend is 0, non-32bit values will have MS bits undefined -int EaCalcRead(int r_ea,int r,int ea,int size,int mask,int sign_extend,int set_nz) +int EaCalcRead(int r_ea,int r,int ea,int size,int mask,EaRWType type,int set_nz) { if (ea<0x10) { if (r_ea==-1) { r_ea=r; - if (!sign_extend) size=2; + if (type == earwt_msb_dont_care) size=2; } } else if (ea==0x3c) // #imm @@ -423,17 +425,12 @@ int EaCalcRead(int r_ea,int r,int ea,int size,int mask,int sign_extend,int set_n if (r_ea==-1) r_ea=0; } - EaCalc (r_ea,mask,ea,size,0,sign_extend); - EaRead (r_ea, r,ea,size,mask,0,sign_extend,set_nz); + EaCalc (r_ea,mask,ea,size,type); + EaRead (r_ea, r,ea,size,mask,type,set_nz); return 0; } -int EaCalcReadNoSE(int r_ea,int r,int ea,int size,int mask) -{ - return EaCalcRead(r_ea,r,ea,size,mask,0); -} - // Return 1 if we can read this ea int EaCanRead(int ea,int size) { @@ -454,21 +451,21 @@ int EaCanRead(int ea,int size) // Write effective address (ARM Register 'a') with ARM register 'v' // Trashes r0-r3,r12,lr; 'a' can be 0 or 2+, 'v' can be 1 or higher // If a==0 and v==1 it's faster though. -int EaWrite(int a,int v,int ea,int size,int mask,int top,int sign_extend_ea) +int EaWrite(int a,int v,int ea,int size,int mask,EaRWType type) { char text[32]=""; int shift=0; if(a == 1) { printf("Error! EaWrite a==1 !\n"); return 1; } - if (top) shift=32-(8<=2||(size==0&&(top||!sign_extend_ea))) { + if (size >= 2 || (size == 0 && type != earwt_sign_extend)) { if(mask) for (i=mask|0x8000; (i&1)==0; i>>=1) low++; // Find out how high up the EA mask is lsl=2-low; // Having a lsl #x here saves one opcode diff --git a/OpArith.cpp b/OpArith.cpp index e956831..8d3e42e 100644 --- a/OpArith.cpp +++ b/OpArith.cpp @@ -37,8 +37,8 @@ int OpArith(int op) OpStart(op, sea, tea); Cycles=4; // imm must be read first - EaCalcReadNoSE(-1,10,sea,size,0); - EaCalcReadNoSE((type!=6)?11:-1,0,tea,size,0x003f); + EaCalcRead(-1,10,sea,size,0,earwt_msb_dont_care); + EaCalcRead((type!=6)?11:-1,0,tea,size,0x003f,earwt_msb_dont_care); if (size<2) shiftstr=(char *)(size?",asl #16":",asl #24"); if (size<2) ot(" mov r10,r10,asl #%i\n",size?16:24); @@ -61,7 +61,7 @@ int OpArith(int op) if (type!=6) { - EaWrite(11, 1, tea,size,0x003f,1); + EaWrite(11, 1, tea,size,0x003f,earwt_shifted_up); } // Correct cycles: @@ -112,7 +112,7 @@ int OpAddq(int op) if (size>0 && (ea&0x38)==0x08) size=2; // addq.w #n,An is also 32-bit - EaCalcReadNoSE(11,0,ea,size,0x003f); + EaCalcRead(11,0,ea,size,0x003f,earwt_msb_dont_care); shift=32-(8<=2)?8:4; else Cycles+=(size>=2)?26:14; @@ -240,7 +240,7 @@ int OpMul(int op) if(type) Cycles=54; else Cycles=sign?158:140; - EaCalcReadNoSE(-1,0,ea,1,0x003f); + EaCalcRead(-1,0,ea,1,0x003f,earwt_msb_dont_care); EaCalc(11,0x0e00,rea, 2); EaRead(11, 2,rea, 2,0x0e00); @@ -344,7 +344,7 @@ int OpMul(int op) } ot("\n"); - EaWrite(11, 1,rea, 2,0x0e00,1); + EaWrite(11, 1,rea, 2,0x0e00,earwt_shifted_up); if (type==0) ot("endofop%.4x%s\n",op,ms?"":":"); OpEnd(ea); @@ -397,15 +397,15 @@ int OpAbcd(int op) if (mem) { ot(";@ Get src/dest EA vals\n"); - EaCalc (0,0x000f, sea,0,1); - EaRead (0, 6, sea,0,0x000f,1); - EaCalcReadNoSE(11,0,dea,0,0x0e00); + EaCalc (0,0x000f, sea,0,earwt_shifted_up); + EaRead (0, 6, sea,0,0x000f,earwt_shifted_up); + EaCalcRead(11,0,dea,0,0x0e00,earwt_msb_dont_care); } else { ot(";@ Get src/dest reg vals\n"); - EaCalcReadNoSE(-1,6,sea,0,0x0007); - EaCalcReadNoSE(11,0,dea,0,0x0e00); + EaCalcRead(-1,6,sea,0,0x0007,earwt_msb_dont_care); + EaCalcRead(11,0,dea,0,0x0e00,earwt_msb_dont_care); ot(" mov r6,r6,asl #24\n"); } ot(" mov r1,r0,asl #24\n\n"); @@ -470,7 +470,7 @@ int OpAbcd(int op) ot(" str r10,[r7,#0x4c] ;@ Save X bit\n"); ot("\n"); - EaWrite(11, 0, dea,0,0x0e00,1); + EaWrite(11, 0, dea,0,0x0e00,earwt_shifted_up); ot(" ldr r6,[r7,#0x54]\n"); OpEnd(sea,dea); @@ -494,7 +494,7 @@ int OpNbcd(int op) OpStart(op,ea); Cycles=6; if(ea >= 8) Cycles+=2; - EaCalcReadNoSE(6,0,ea,0,0x003f); + EaCalcRead(6,0,ea,0,0x003f,earwt_msb_dont_care); // this is rewrite of Musashi's code ot(" ldr r2,[r7,#0x4c]\n"); @@ -520,7 +520,7 @@ int OpNbcd(int op) ot(" orr r10,r10,#0x20000000 ;@ C\n"); ot("\n"); - EaWrite(6, 1, ea,0,0x3f,0,0); + EaWrite(6, 1, ea,0,0x3f,earwt_msb_dont_care); ot("finish%.4x%s\n",op,ms?"":":"); ot(" tst r11,r11\n"); @@ -564,14 +564,14 @@ int OpAritha(int op) // different emus act differently in this situation, I couldn't fugure which is right behaviour. //if (type == 1) { - EaCalcReadNoSE(-1,0,sea,size,0x003f); - EaCalcReadNoSE(type!=1?11:-1,1,dea,2,0x0e00); + EaCalcRead(-1,0,sea,size,0x003f,earwt_msb_dont_care); + EaCalcRead(type!=1?11:-1,1,dea,2,0x0e00,earwt_msb_dont_care); } #if 0 else { - EaCalcReadNoSE(type!=1?11:-1,1,dea,2,0x0e00); - EaCalcReadNoSE(-1,0,sea,size,0x003f); + EaCalcRead(type!=1?11:-1,1,dea,2,0x0e00,earwt_msb_dont_care); + EaCalcRead(-1,0,sea,size,0x003f,earwt_msb_dont_care); } #endif @@ -623,15 +623,15 @@ int OpAddx(int op) if (mem) { ot(";@ Get src/dest EA vals\n"); - EaCalc (0,0x000f, sea,size,1); - EaRead (0, 6, sea,size,0x000f,1); - EaCalcReadNoSE(11,0,dea,size,0x0e00); + EaCalc (0,0x000f, sea,size,earwt_shifted_up); + EaRead (0, 6, sea,size,0x000f,earwt_shifted_up); + EaCalcRead(11,0,dea,size,0x0e00,earwt_msb_dont_care); } else { ot(";@ Get src/dest reg vals\n"); - EaCalcReadNoSE(-1,6,sea,size,0x0007); - EaCalcReadNoSE(11,0,dea,size,0x0e00); + EaCalcRead(-1,6,sea,size,0x0007,earwt_msb_dont_care); + EaCalcRead(11,0,dea,size,0x0e00,earwt_msb_dont_care); if (size<2) ot(" mov r6,r6,asl #%d\n\n",size?16:24); } @@ -660,7 +660,7 @@ int OpAddx(int op) ot("\n"); ot(";@ Save result:\n"); - EaWrite(11, 1, dea,size,0x0e00,1); + EaWrite(11, 1, dea,size,0x0e00,earwt_shifted_up); ot(" ldr r6,[r7,#0x54]\n"); OpEnd(sea,dea); @@ -702,10 +702,10 @@ int OpCmpEor(int op) } ot(";@ Get EA into r11 and value into r0:\n"); - EaCalcReadNoSE(eor?11:-1,0,ea,size,0x003f); + EaCalcRead(eor?11:-1,0,ea,size,0x003f,earwt_msb_dont_care); ot(";@ Get register operand into r1:\n"); - EaCalcReadNoSE(-1,1,rea,size,0x0e00); + EaCalcRead(-1,1,rea,size,0x0e00,earwt_msb_dont_care); if (size<2) ot(" mov r0,r0,asl #%d\n\n",size?16:24); if (size<2) asl=(char *)(size?",asl #16":",asl #24"); @@ -723,7 +723,7 @@ int OpCmpEor(int op) } ot("\n"); - if (eor) EaWrite(11, 1,ea,size,0x003f,1); + if (eor) EaWrite(11, 1,ea,size,0x003f,earwt_shifted_up); OpEnd(ea); return 0; @@ -748,11 +748,11 @@ int OpCmpm(int op) OpStart(op,sea); Cycles=4; ot(";@ Get src operand into r11:\n"); - EaCalc (0,0x0007, sea,size,1); - EaRead (0, 11, sea,size,0x0007,1); + EaCalc (0,0x0007, sea,size,earwt_shifted_up); + EaRead (0, 11, sea,size,0x0007,earwt_shifted_up); ot(";@ Get dst operand into r0:\n"); - EaCalcReadNoSE(-1,0,dea,size,0x0e00); + EaCalcRead(-1,0,dea,size,0x0e00,earwt_msb_dont_care); if (size<2) asl=(char *)(size?",asl #16":",asl #24"); @@ -791,10 +791,10 @@ int OpChk(int op) OpStart(op,ea); Cycles=10; ot(";@ Get value into r0:\n"); - EaCalcReadNoSE(-1,0,ea,size,0x003f); + EaCalcRead(-1,0,ea,size,0x003f,earwt_msb_dont_care); ot(";@ Get register operand into r1:\n"); - EaCalcReadNoSE(-1,1,rea,size,0x0e00); + EaCalcRead(-1,1,rea,size,0x0e00,earwt_msb_dont_care); if (size<2) ot(" mov r0,r0,asl #%d\n",size?16:24); diff --git a/OpBranch.cpp b/OpBranch.cpp index 051c373..9a7c8da 100644 --- a/OpBranch.cpp +++ b/OpBranch.cpp @@ -113,8 +113,8 @@ int OpLink(int op) if(reg!=7) { ot(";@ Get An\n"); - EaCalc(11, 7, 8, 2, 1); - EaRead(11, 1, 8, 2, 7, 1); + EaCalc(11, 7, 8, 2); + EaRead(11, 1, 8, 2, 7); } ot(" ldr r0,[r7,#0x3c] ;@ Get A7\n"); @@ -128,7 +128,7 @@ int OpLink(int op) ot(";@ Save to An\n"); if(reg!=7) - EaWrite(11,8, 8, 2, 7, 1); + EaWrite(11, 8, 8, 2, 7); ot(";@ Get offset:\n"); EaCalc(0,0,0x3c,1); // abused r8 is ok because of imm EA @@ -154,8 +154,8 @@ int OpUnlk(int op) OpStart(op,0x10); ot(";@ Get An\n"); - EaCalc(11, 0xf, 8, 2, 1); - EaRead(11, 0, 8, 2, 0xf, 1); + EaCalc(11, 0xf, 8, 2); + EaRead(11, 0, 8, 2, 0xf); ot(" add r8,r0,#4 ;@ A7+=4, abuse r8\n"); ot("\n"); @@ -165,7 +165,7 @@ int OpUnlk(int op) ot(" str r8,[r7,#0x3c] ;@ Save A7\n"); ot("\n"); ot(";@ An = value from stack:\n"); - EaWrite(11, 0, 8, 2, 7, 1); + EaWrite(11, 0, 8, 2, 7); Cycles=12; OpEnd(0x10); diff --git a/OpLogic.cpp b/OpLogic.cpp index 4d4312c..012e35a 100644 --- a/OpLogic.cpp +++ b/OpLogic.cpp @@ -126,9 +126,9 @@ int OpBtstReg(int op) if(size>=2) Cycles+=2; } - EaCalcReadNoSE(-1,11,sea,0,0x0e00); + EaCalcRead(-1,11,sea,0,0x0e00,earwt_msb_dont_care); - EaCalcReadNoSE((type>0)?8:-1,0,tea,size,0x003f); + EaCalcRead((type>0)?8:-1,0,tea,size,0x003f,earwt_msb_dont_care); if (tea>=0x10) ot(" and r11,r11,#7 ;@ mem - do mod 8\n"); // size always 0 @@ -147,7 +147,7 @@ int OpBtstReg(int op) if (type==2) ot(" bic r1,r0,r1,lsl r11 ;@ Clear bit\n"); if (type==3) ot(" orr r1,r0,r1,lsl r11 ;@ Set bit\n"); ot("\n"); - EaWrite(8,1,tea,size,0x003f,0,0); + EaWrite(8,1,tea,size,0x003f,earwt_msb_dont_care); } OpEnd(tea); @@ -181,7 +181,7 @@ int OpBtstImm(int op) OpStart(op,sea,tea); ot("\n"); - EaCalcReadNoSE(-1,0,sea,0,0); + EaCalcRead(-1,0,sea,0,0,earwt_msb_dont_care); ot(" mov r11,#1\n"); ot(" bic r10,r10,#0x40000000 ;@ Blank Z flag\n"); if (tea>=0x10) @@ -197,7 +197,7 @@ int OpBtstImm(int op) if(size>=2) Cycles+=2; } - EaCalcReadNoSE((type>0)?8:-1,0,tea,size,0x003f); + EaCalcRead((type>0)?8:-1,0,tea,size,0x003f,earwt_msb_dont_care); ot(" tst r0,r11 ;@ Do arithmetic\n"); ot(" orreq r10,r10,#0x40000000 ;@ Get Z flag\n"); ot("\n"); @@ -208,7 +208,7 @@ int OpBtstImm(int op) if (type==2) ot(" bic r1,r0,r11 ;@ Clear bit\n"); if (type==3) ot(" orr r1,r0,r11 ;@ Set bit\n"); ot("\n"); - EaWrite(8, 1,tea,size,0x003f,0,0); + EaWrite(8, 1,tea,size,0x003f,earwt_msb_dont_care); #if CYCLONE_FOR_GENESIS && !MEMHANDLERS_CHANGE_CYCLES // this is a bit hacky (device handlers might modify cycles) if (tea==0x38||tea==0x39) @@ -241,9 +241,9 @@ int OpNeg(int op) OpStart(op,ea); Cycles=size<2?4:6; if(ea >= 0x10) Cycles*=2; - EaCalc (11,0x003f,ea,size,0,0); + EaCalc (11,0x003f,ea,size,earwt_msb_dont_care); - if (type!=1) EaRead (11,0,ea,size,0x003f,0,0); // Don't need to read for 'clr' (or do we, for a dummy read?) + if (type!=1) EaRead (11,0,ea,size,0x003f,earwt_msb_dont_care); // Don't need to read for 'clr' (or do we, for a dummy read?) if (type==1) ot("\n"); if (type==0) @@ -294,7 +294,7 @@ int OpNeg(int op) } if (type==1) eawrite_check_addrerr=1; - EaWrite(11, 1,ea,size,0x003f,0,0); + EaWrite(11, 1,ea,size,0x003f,earwt_msb_dont_care); OpEnd(ea); @@ -314,13 +314,13 @@ int OpSwap(int op) OpStart(op); Cycles=4; - EaCalc (11,0x0007,ea,2,1); - EaRead (11, 0,ea,2,0x0007,1); + EaCalc (11,0x0007,ea,2,earwt_shifted_up); + EaRead (11, 0,ea,2,0x0007,earwt_shifted_up); ot(" movs r1,r0,ror #16\n"); OpGetFlagsNZ(1); - EaWrite(11, 1,8,2,0x0007,1); + EaWrite(11, 1,8,2,0x0007,earwt_shifted_up); OpEnd(); @@ -345,8 +345,8 @@ int OpTst(int op) OpStart(op,sea); Cycles=4; - EaCalc (0,0x003f,sea,size,1); - EaRead (0, 0,sea,size,0x003f,1,0,1); + EaCalc (0,0x003f,sea,size,earwt_shifted_up); + EaRead (0, 0,sea,size,0x003f,earwt_shifted_up,1); OpGetFlagsNZ(0); ot("\n"); @@ -372,15 +372,15 @@ int OpExt(int op) OpStart(op); Cycles=4; - EaCalc (11,0x0007,ea,size+1,0,0); - EaRead (11, 0,ea,size+1,0x0007,0,0); + EaCalc (11,0x0007,ea,size+1,earwt_msb_dont_care); + EaRead (11, 0,ea,size+1,0x0007,earwt_msb_dont_care); ot(" movs r0,r0,asl #%d\n",shift); OpGetFlagsNZ(0); ot(" mov r1,r0,asr #%d\n",shift); ot("\n"); - EaWrite(11, 1,ea,size+1,0x0007,0,0); + EaWrite(11, 1,ea,size+1,0x0007,earwt_msb_dont_care); OpEnd(); return 0; @@ -429,8 +429,8 @@ int OpSet(int op) ot("\n"); eawrite_check_addrerr=1; - EaCalc (0,0x003f, ea,size,0,0); - EaWrite(0, 1, ea,size,0x003f,0,0); + EaCalc (0,0x003f, ea,size,earwt_msb_dont_care); + EaWrite(0, 1, ea,size,0x003f,earwt_msb_dont_care); opend_op_changes_cycles=changed_cycles; OpEnd(ea,0); @@ -678,12 +678,12 @@ int OpAsr(int op) OpStart(op,ea,0,count<0); Cycles=size<2?6:8; - EaCalc(11,0x0007, ea,size,1); - EaRead(11, 0, ea,size,0x0007,1); + EaCalc(11,0x0007, ea,size,earwt_shifted_up); + EaRead(11, 0, ea,size,0x0007,earwt_shifted_up); EmitAsr(op,type,dir,count, size,usereg); - EaWrite(11, 0, ea,size,0x0007,1); + EaWrite(11, 0, ea,size,0x0007,earwt_shifted_up); opend_op_changes_cycles = (count<0); OpEnd(ea,0); @@ -710,12 +710,12 @@ int OpAsrEa(int op) OpStart(op,ea); Cycles=6; // EmitAsr() will add 2 - EaCalc (11,0x003f,ea,size,1); - EaRead (11, 0,ea,size,0x003f,1); + EaCalc (11,0x003f,ea,size,earwt_shifted_up); + EaRead (11, 0,ea,size,0x003f,earwt_shifted_up); EmitAsr(op,type,dir,1,size,0); - EaWrite(11, 0,ea,size,0x003f,1); + EaWrite(11, 0,ea,size,0x003f,earwt_shifted_up); OpEnd(ea); return 0; @@ -741,8 +741,8 @@ int OpTas(int op, int gen_special) Cycles=4; if(ea>=8) Cycles+=10; - EaCalc (11,0x003f,ea,0,1); - EaRead (11, 1,ea,0,0x003f,1,0,1); + EaCalc (11,0x003f,ea,0,earwt_shifted_up); + EaRead (11, 1,ea,0,0x003f,earwt_shifted_up,1); OpGetFlagsNZ(1); ot("\n"); @@ -753,7 +753,7 @@ int OpTas(int op, int gen_special) #endif ot(" orr r1,r1,#0x80000000 ;@ set bit7\n"); - EaWrite(11, 1,ea,0,0x003f,1); + EaWrite(11, 1,ea,0,0x003f,earwt_shifted_up); #if CYCLONE_FOR_GENESIS } #endif diff --git a/OpMove.cpp b/OpMove.cpp index 82c589c..3d893de 100644 --- a/OpMove.cpp +++ b/OpMove.cpp @@ -133,30 +133,30 @@ int OpMove(int op) if (movea==0) { - EaCalcRead(-1,1,sea,size,0x003f,1,1); + EaCalcRead(-1,1,sea,size,0x003f,earwt_sign_extend,1); OpGetFlagsNZ(1); ot("\n"); } else { - EaCalcRead(-1,1,sea,size,0x003f); + EaCalcRead(-1,1,sea,size,0x003f,earwt_sign_extend); size=2; // movea always expands to 32-bits } eawrite_check_addrerr=1; #if SPLIT_MOVEL_PD if ((tea&0x38)==0x20 && size==2) { // -(An) - EaCalc (8,0x0e00,tea,size,0,0); + EaCalc (8,0x0e00,tea,size,earwt_msb_dont_care); ot(" mov r11,r1\n"); ot(" add r0,r8,#2\n"); - EaWrite(0, 1,tea,1,0x0e00,0,0); - EaWrite(8, 11,tea,1,0x0e00,1); + EaWrite(0, 1,tea,1,0x0e00,earwt_msb_dont_care); + EaWrite(8, 11,tea,1,0x0e00,earwt_shifted_up); } else #endif { - EaCalc (0,0x0e00,tea,size,0,0); - EaWrite(0, 1,tea,size,0x0e00,0,0); + EaCalc (0,0x0e00,tea,size,earwt_msb_dont_care); + EaWrite(0, 1,tea,size,0x0e00,earwt_msb_dont_care); } #if CYCLONE_FOR_GENESIS && !MEMHANDLERS_CHANGE_CYCLES @@ -239,13 +239,13 @@ int OpMoveSr(int op) { eawrite_check_addrerr=1; OpFlagsToReg(type==0); - EaCalc (0,0x003f,ea,size,0,0); - EaWrite(0, 1,ea,size,0x003f,0,0); + EaCalc (0,0x003f,ea,size,earwt_msb_dont_care); + EaWrite(0, 1,ea,size,0x003f,earwt_msb_dont_care); } if (type==2 || type==3) { - EaCalcReadNoSE(-1,0,ea,size,0x003f); + EaCalcRead(-1,0,ea,size,0x003f,earwt_msb_dont_care); OpRegToFlags(type==3,1); if (type==3) { SuperChange(op,1); @@ -278,7 +278,7 @@ int OpArithSr(int op) OpStart(op,ea,0,0,size!=0); Cycles=16; - EaCalcRead(-1,0,ea,size,0x003f); + EaCalcRead(-1,0,ea,size,0x003f,earwt_sign_extend); ot(" eor r1,r0,r0,ror #1 ;@ Bit 0=C^V\n"); ot(" tst r1,#1 ;@ 1 if C!=V\n"); @@ -435,10 +435,10 @@ int OpMovem(int op) #if SPLIT_MOVEL_PD if (decr && size==2) { // -(An) ot(" add r0,r6,#2\n"); - EaWrite(0,1,ea,1,0x003f,0,0); + EaWrite(0,1,ea,1,0x003f,earwt_msb_dont_care); ot(" ldr r1,[r7,r4] ;@ Load value from Dn/An\n"); ot(" mov r0,r6\n"); - EaWrite(0,1,ea,1,0x003f,1); + EaWrite(0,1,ea,1,0x003f,earwt_shifted_up); } else #endif @@ -500,13 +500,13 @@ int OpMoveUsp(int op) { eawrite_check_addrerr=1; ot(" ldr r1,[r7,#0x48] ;@ Get from USP\n\n"); - EaCalc (0,0x000f,8,2,1); - EaWrite(0, 1,8,2,0x000f,1); + EaCalc (0,0x000f,8,2); + EaWrite(0, 1,8,2,0x000f); } else { - EaCalc (0,0x000f,8,2,1); - EaRead (0, 0,8,2,0x000f,1); + EaCalc (0,0x000f,8,2); + EaRead (0, 0,8,2,0x000f); ot(" str r0,[r7,#0x48] ;@ Put in USP\n\n"); } @@ -595,7 +595,7 @@ int OpMovep(int op) if(dir) // reg to mem { - EaCalcReadNoSE(-1,11,rea,size,0x0e00); + EaCalcRead(-1,11,rea,size,0x0e00,earwt_msb_dont_care); EaCalc(8,0x000f,ea,size); if(size==2) { // if operand is long @@ -616,24 +616,24 @@ int OpMovep(int op) } else // mem to reg { - EaCalc(6,0x000f,ea,size,1); - EaRead(6,11,ea,0,0x000f,1); // read first byte + EaCalc(6,0x000f,ea,size,earwt_shifted_up); + EaRead(6,11,ea,0,0x000f,earwt_shifted_up); // read first byte ot(" add r0,r6,#2\n"); - EaRead(0,1,ea,0,0x000f,1); // read second byte + EaRead(0,1,ea,0,0x000f,earwt_shifted_up); // read second byte if(size==2) { // if operand is long ot(" orr r11,r11,r1,lsr #8 ;@ second byte\n"); ot(" add r0,r6,#4\n"); - EaRead(0,1,ea,0,0x000f,1); + EaRead(0,1,ea,0,0x000f,earwt_shifted_up); ot(" orr r11,r11,r1,lsr #16 ;@ third byte\n"); ot(" add r0,r6,#6\n"); - EaRead(0,1,ea,0,0x000f,1); + EaRead(0,1,ea,0,0x000f,earwt_shifted_up); ot(" orr r1,r11,r1,lsr #24 ;@ fourth byte\n"); } else { ot(" orr r1,r11,r1,lsr #8 ;@ second byte\n"); } // store the result - EaCalc(0,0x0e00,rea,size,1); - EaWrite(0,1,rea,size,0x0e00,1); + EaCalc(0,0x0e00,rea,size,earwt_shifted_up); + EaWrite(0,1,rea,size,0x0e00,earwt_shifted_up); ot(" ldr r6,[r7,#0x54]\n"); } diff --git a/app.h b/app.h index f041dff..cffd2cb 100644 --- a/app.h +++ b/app.h @@ -24,6 +24,13 @@ #include "Disa/Disa.h" // Ea.cpp +enum EaRWType { + earwt_sign_extend = 1, + earwt_zero_extend, + earwt_shifted_up, + earwt_msb_dont_care, +}; + extern int earead_check_addrerr; extern int eawrite_check_addrerr; extern int g_jmp_cycle_table[]; @@ -32,12 +39,11 @@ extern int g_lea_cycle_table[]; extern int g_pea_cycle_table[]; extern int g_movem_cycle_table[]; int Ea_add_ns(int *tab, int ea); // add nonstandard EA cycles -int EaCalc(int a,int mask,int ea,int size,int top=0,int sign_extend=1); // 6 -int EaRead(int a,int v,int ea,int size,int mask,int top=0,int sign_extend=1,int set_nz=0); // 8 -int EaCalcRead(int r_ea,int r,int ea,int size,int mask,int sign_extend=1,int set_nz=0); // 7 -int EaCalcReadNoSE(int r_ea,int r,int ea,int size,int mask); +int EaCalc(int a,int mask,int ea,int size,EaRWType type=earwt_sign_extend); // 6 +int EaRead(int a,int v,int ea,int size,int mask,EaRWType type=earwt_sign_extend,int set_nz=0); // 8 +int EaCalcRead(int r_ea,int r,int ea,int size,int mask,EaRWType type=earwt_sign_extend,int set_nz=0); // 7 int EaCanRead(int ea,int size); -int EaWrite(int a,int v,int ea,int size,int mask,int top=0,int sign_extend_ea=1); +int EaWrite(int a,int v,int ea,int size,int mask,EaRWType type=earwt_sign_extend); int EaCanWrite(int ea); int EaAn(int ea);