// If ea>=0x10, trashes r0,r2 and r3, else nothing\r
// size values 0, 1, 2 ~ byte, word, long\r
// mask shows usable bits in r8\r
-int EaCalc(int a,int mask,int ea,int size,int top,int sign_extend)\r
+int EaCalc(int a,int mask,int ea,int size,EaRWType type)\r
{\r
char text[32]="";\r
\r
\r
if (ea<0x10)\r
{\r
+ // Saves one opcode as we can shift in ldr/str\r
int noshift=0;\r
- if (size>=2||(size==0&&(top||!sign_extend))) noshift=1; // Saves one opcode\r
+ if (size >= 2 || (size == 0 && type != earwt_sign_extend)) noshift=1;\r
\r
ot(";@ EaCalc : Get register index into r%d:\n",a);\r
\r
// ---------------------------------------------------------------------------\r
// Read effective address in (ARM Register 'a') to ARM register 'v'\r
// 'a' and 'v' can be anything but 0 is generally best (for both)\r
-// If (ea<0x10) nothing is trashed, else r0-r3 is trashed\r
-// If 'top' is given, the ARM register v shifted to the top, e.g. 0xc000 -> 0xc0000000\r
-// If top is 0 and sign_extend is not, then ARM register v is sign extended,\r
-// e.g. 0xc000 -> 0xffffc000 (else it may or may not be sign extended)\r
-\r
-int EaRead(int a,int v,int ea,int size,int mask,int top,int sign_extend,int set_nz)\r
+// If (ea<0x10) nothing is trashed, else r0-r3,r12 is trashed\r
+int EaRead(int a,int v,int ea,int size,int mask,EaRWType type,int set_nz)\r
{\r
char text[32]="";\r
const char *s="";\r
int flags_set=0;\r
int shift=0;\r
\r
- if (set_nz) s="s";\r
+ if (set_nz) {\r
+ if (type == earwt_msb_dont_care || type == earwt_zero_extend) {\r
+ fprintf(stderr, "set_nz on msb_dont_care/zero_extend?\n");\r
+ exit(1);\r
+ }\r
+ s="s";\r
+ }\r
\r
shift=32-(8<<size);\r
\r
if (ea<0x10)\r
{\r
int lsl=0,low=0,nsarm=size&3,i;\r
- if (size>=2||(size==0&&(top||!sign_extend))) {\r
- if(mask)\r
+ if (size >= 2 || (size == 0 && type != earwt_sign_extend)) {\r
+ if (mask)\r
for (i=mask|0x8000; (i&1)==0; i>>=1) low++; // Find out how high up the EA mask is\r
lsl=2-low; // Having a lsl #2 here saves one opcode\r
}\r
\r
- if (top||!sign_extend) nsarm=3;\r
+ if (type == earwt_shifted_up || type == earwt_msb_dont_care)\r
+ // use plain ldr\r
+ nsarm = 3;\r
\r
ot(";@ EaRead : Read register[r%d] into r%d:\n",a,v);\r
\r
else if (lsl<0) ot(" ldr%s r%d,[r7,r%d,lsr #%i]\n",Narm[nsarm],v,a,-lsl);\r
else ot(" ldr%s r%d,[r7,r%d]\n",Sarm[nsarm],v,a);\r
\r
- if (top&&shift) ot(" mov%s r%d,r%d,asl #%d\n",s,v,v,shift);\r
- else if(set_nz) ot(" tst r%d,r%d\n",v,v);\r
+ if (type == earwt_shifted_up && shift)\r
+ ot(" mov%s r%d,r%d,asl #%d\n",s,v,v,shift);\r
+ else if (set_nz)\r
+ ot(" tst r%d,r%d\n",v,v);\r
\r
ot("\n"); return 0;\r
}\r
{\r
int asl=0;\r
\r
- if (top) asl=shift;\r
+ if (type == earwt_shifted_up) asl = shift;\r
\r
if (asl) ot(" mov%s r%d,r%d,asl #%d\n",s,v,a,asl);\r
else if (v!=a) ot(" mov%s r%d,r%d\n",s,v,a);\r
// defaults to 1, as most things begins with a read\r
earead_check_addrerr=1;\r
\r
- if (sign_extend)\r
+ if (type == earwt_sign_extend)\r
{\r
int d_reg=0;\r
if (shift) {\r
- ot(" mov%s r%d,r%d,asl #%d\n",s,v,d_reg,shift);\r
- d_reg=v;\r
- flags_set=1;\r
- }\r
- if (!top && shift) {\r
- ot(" mov%s r%d,r%d,asr #%d\n",s,v,d_reg,shift);\r
+ ot(" mov r%d,r%d,asl #%d\n",v,d_reg,shift);\r
+ ot(" mov%s r%d,r%d,asr #%d\n",s,v,v,shift);\r
d_reg=v;\r
flags_set=1;\r
}\r
}\r
else\r
{\r
- if (top && shift) {\r
+ if (type == earwt_shifted_up && shift) {\r
ot(" mov%s r%d,r0,asl #%d\n",s,v,shift);\r
flags_set=1;\r
}\r
// else r0-r3 are trashed\r
// size values 0, 1, 2 ~ byte, word, long\r
// r_ea is reg to store ea in (-1 means ea is not needed), r is dst reg\r
-// if sign_extend is 0, non-32bit values will have MS bits undefined\r
-int EaCalcRead(int r_ea,int r,int ea,int size,int mask,int sign_extend,int set_nz)\r
+int EaCalcRead(int r_ea,int r,int ea,int size,int mask,EaRWType type,int set_nz)\r
{\r
if (ea<0x10)\r
{\r
if (r_ea==-1)\r
{\r
r_ea=r;\r
- if (!sign_extend) size=2;\r
+ if (type == earwt_msb_dont_care) size=2;\r
}\r
}\r
else if (ea==0x3c) // #imm\r
if (r_ea==-1) r_ea=0;\r
}\r
\r
- EaCalc (r_ea,mask,ea,size,0,sign_extend);\r
- EaRead (r_ea, r,ea,size,mask,0,sign_extend,set_nz);\r
+ EaCalc (r_ea,mask,ea,size,type);\r
+ EaRead (r_ea, r,ea,size,mask,type,set_nz);\r
\r
return 0;\r
}\r
\r
-int EaCalcReadNoSE(int r_ea,int r,int ea,int size,int mask)\r
-{\r
- return EaCalcRead(r_ea,r,ea,size,mask,0);\r
-}\r
-\r
// Return 1 if we can read this ea\r
int EaCanRead(int ea,int size)\r
{\r
// Write effective address (ARM Register 'a') with ARM register 'v'\r
// Trashes r0-r3,r12,lr; 'a' can be 0 or 2+, 'v' can be 1 or higher\r
// If a==0 and v==1 it's faster though.\r
-int EaWrite(int a,int v,int ea,int size,int mask,int top,int sign_extend_ea)\r
+int EaWrite(int a,int v,int ea,int size,int mask,EaRWType type)\r
{\r
char text[32]="";\r
int shift=0;\r
\r
if(a == 1) { printf("Error! EaWrite a==1 !\n"); return 1; }\r
\r
- if (top) shift=32-(8<<size);\r
+ if (type == earwt_shifted_up) shift=32-(8<<size);\r
\r
DisaPc=2; DisaGetEa(text,ea,size); // Get text version of the effective address\r
\r
if (ea<0x10)\r
{\r
int lsl=0,low=0,i;\r
- if (size>=2||(size==0&&(top||!sign_extend_ea))) {\r
+ if (size >= 2 || (size == 0 && type != earwt_sign_extend)) {\r
if(mask)\r
for (i=mask|0x8000; (i&1)==0; i>>=1) low++; // Find out how high up the EA mask is\r
lsl=2-low; // Having a lsl #x here saves one opcode\r
OpStart(op, sea, tea); Cycles=4;\r
\r
// imm must be read first\r
- EaCalcReadNoSE(-1,10,sea,size,0);\r
- EaCalcReadNoSE((type!=6)?11:-1,0,tea,size,0x003f);\r
+ EaCalcRead(-1,10,sea,size,0,earwt_msb_dont_care);\r
+ EaCalcRead((type!=6)?11:-1,0,tea,size,0x003f,earwt_msb_dont_care);\r
\r
if (size<2) shiftstr=(char *)(size?",asl #16":",asl #24");\r
if (size<2) ot(" mov r10,r10,asl #%i\n",size?16:24);\r
\r
if (type!=6)\r
{\r
- EaWrite(11, 1, tea,size,0x003f,1);\r
+ EaWrite(11, 1, tea,size,0x003f,earwt_shifted_up);\r
}\r
\r
// Correct cycles:\r
\r
if (size>0 && (ea&0x38)==0x08) size=2; // addq.w #n,An is also 32-bit\r
\r
- EaCalcReadNoSE(11,0,ea,size,0x003f);\r
+ EaCalcRead(11,0,ea,size,0x003f,earwt_msb_dont_care);\r
\r
shift=32-(8<<size);\r
\r
if ((ea&0x38)!=0x08) OpGetFlags(type,1);\r
ot("\n");\r
\r
- EaWrite(11, 1, ea,size,0x003f,1);\r
+ EaWrite(11, 1, ea,size,0x003f,earwt_shifted_up);\r
\r
OpEnd(ea);\r
\r
\r
OpStart(op,ea); Cycles=4;\r
\r
- EaCalcReadNoSE(dir?11:-1,0,ea,size,0x003f);\r
+ EaCalcRead(dir?11:-1,0,ea,size,0x003f,earwt_msb_dont_care);\r
\r
- EaCalcReadNoSE(dir?-1:11,1,rea,size,0x0e00);\r
+ EaCalcRead(dir?-1:11,1,rea,size,0x0e00,earwt_msb_dont_care);\r
\r
ot(";@ Do arithmetic:\n");\r
if (type==0) strop = "orrs";\r
\r
ot(";@ Save result:\n");\r
if (size<2) ot(" mov r1,r1,asr #%d\n",size?16:24);\r
- if (dir) EaWrite(11, 1, ea,size,0x003f,0,0);\r
- else EaWrite(11, 1,rea,size,0x0e00,0,0);\r
+ if (dir) EaWrite(11, 1, ea,size,0x003f,earwt_msb_dont_care);\r
+ else EaWrite(11, 1,rea,size,0x0e00,earwt_msb_dont_care);\r
\r
if(rea==ea) {\r
if(ea<8) Cycles=(size>=2)?8:4; else Cycles+=(size>=2)?26:14;\r
if(type) Cycles=54;\r
else Cycles=sign?158:140;\r
\r
- EaCalcReadNoSE(-1,0,ea,1,0x003f);\r
+ EaCalcRead(-1,0,ea,1,0x003f,earwt_msb_dont_care);\r
\r
EaCalc(11,0x0e00,rea, 2);\r
EaRead(11, 2,rea, 2,0x0e00);\r
}\r
ot("\n");\r
\r
- EaWrite(11, 1,rea, 2,0x0e00,1);\r
+ EaWrite(11, 1,rea, 2,0x0e00,earwt_shifted_up);\r
\r
if (type==0) ot("endofop%.4x%s\n",op,ms?"":":");\r
OpEnd(ea);\r
if (mem)\r
{\r
ot(";@ Get src/dest EA vals\n");\r
- EaCalc (0,0x000f, sea,0,1);\r
- EaRead (0, 6, sea,0,0x000f,1);\r
- EaCalcReadNoSE(11,0,dea,0,0x0e00);\r
+ EaCalc (0,0x000f, sea,0,earwt_shifted_up);\r
+ EaRead (0, 6, sea,0,0x000f,earwt_shifted_up);\r
+ EaCalcRead(11,0,dea,0,0x0e00,earwt_msb_dont_care);\r
}\r
else\r
{\r
ot(";@ Get src/dest reg vals\n");\r
- EaCalcReadNoSE(-1,6,sea,0,0x0007);\r
- EaCalcReadNoSE(11,0,dea,0,0x0e00);\r
+ EaCalcRead(-1,6,sea,0,0x0007,earwt_msb_dont_care);\r
+ EaCalcRead(11,0,dea,0,0x0e00,earwt_msb_dont_care);\r
ot(" mov r6,r6,asl #24\n");\r
}\r
ot(" mov r1,r0,asl #24\n\n");\r
ot(" str r10,[r7,#0x4c] ;@ Save X bit\n");\r
ot("\n");\r
\r
- EaWrite(11, 0, dea,0,0x0e00,1);\r
+ EaWrite(11, 0, dea,0,0x0e00,earwt_shifted_up);\r
\r
ot(" ldr r6,[r7,#0x54]\n");\r
OpEnd(sea,dea);\r
OpStart(op,ea); Cycles=6;\r
if(ea >= 8) Cycles+=2;\r
\r
- EaCalcReadNoSE(6,0,ea,0,0x003f);\r
+ EaCalcRead(6,0,ea,0,0x003f,earwt_msb_dont_care);\r
\r
// this is rewrite of Musashi's code\r
ot(" ldr r2,[r7,#0x4c]\n");\r
ot(" orr r10,r10,#0x20000000 ;@ C\n");\r
ot("\n");\r
\r
- EaWrite(6, 1, ea,0,0x3f,0,0);\r
+ EaWrite(6, 1, ea,0,0x3f,earwt_msb_dont_care);\r
\r
ot("finish%.4x%s\n",op,ms?"":":");\r
ot(" tst r11,r11\n");\r
// different emus act differently in this situation, I couldn't fugure which is right behaviour.\r
//if (type == 1)\r
{\r
- EaCalcReadNoSE(-1,0,sea,size,0x003f);\r
- EaCalcReadNoSE(type!=1?11:-1,1,dea,2,0x0e00);\r
+ EaCalcRead(-1,0,sea,size,0x003f,earwt_msb_dont_care);\r
+ EaCalcRead(type!=1?11:-1,1,dea,2,0x0e00,earwt_msb_dont_care);\r
}\r
#if 0\r
else\r
{\r
- EaCalcReadNoSE(type!=1?11:-1,1,dea,2,0x0e00);\r
- EaCalcReadNoSE(-1,0,sea,size,0x003f);\r
+ EaCalcRead(type!=1?11:-1,1,dea,2,0x0e00,earwt_msb_dont_care);\r
+ EaCalcRead(-1,0,sea,size,0x003f,earwt_msb_dont_care);\r
}\r
#endif\r
\r
if (mem)\r
{\r
ot(";@ Get src/dest EA vals\n");\r
- EaCalc (0,0x000f, sea,size,1);\r
- EaRead (0, 6, sea,size,0x000f,1);\r
- EaCalcReadNoSE(11,0,dea,size,0x0e00);\r
+ EaCalc (0,0x000f, sea,size,earwt_shifted_up);\r
+ EaRead (0, 6, sea,size,0x000f,earwt_shifted_up);\r
+ EaCalcRead(11,0,dea,size,0x0e00,earwt_msb_dont_care);\r
}\r
else\r
{\r
ot(";@ Get src/dest reg vals\n");\r
- EaCalcReadNoSE(-1,6,sea,size,0x0007);\r
- EaCalcReadNoSE(11,0,dea,size,0x0e00);\r
+ EaCalcRead(-1,6,sea,size,0x0007,earwt_msb_dont_care);\r
+ EaCalcRead(11,0,dea,size,0x0e00,earwt_msb_dont_care);\r
if (size<2) ot(" mov r6,r6,asl #%d\n\n",size?16:24);\r
}\r
\r
ot("\n");\r
\r
ot(";@ Save result:\n");\r
- EaWrite(11, 1, dea,size,0x0e00,1);\r
+ EaWrite(11, 1, dea,size,0x0e00,earwt_shifted_up);\r
\r
ot(" ldr r6,[r7,#0x54]\n");\r
OpEnd(sea,dea);\r
}\r
\r
ot(";@ Get EA into r11 and value into r0:\n");\r
- EaCalcReadNoSE(eor?11:-1,0,ea,size,0x003f);\r
+ EaCalcRead(eor?11:-1,0,ea,size,0x003f,earwt_msb_dont_care);\r
\r
ot(";@ Get register operand into r1:\n");\r
- EaCalcReadNoSE(-1,1,rea,size,0x0e00);\r
+ EaCalcRead(-1,1,rea,size,0x0e00,earwt_msb_dont_care);\r
\r
if (size<2) ot(" mov r0,r0,asl #%d\n\n",size?16:24);\r
if (size<2) asl=(char *)(size?",asl #16":",asl #24");\r
}\r
ot("\n");\r
\r
- if (eor) EaWrite(11, 1,ea,size,0x003f,1);\r
+ if (eor) EaWrite(11, 1,ea,size,0x003f,earwt_shifted_up);\r
\r
OpEnd(ea);\r
return 0;\r
OpStart(op,sea); Cycles=4;\r
\r
ot(";@ Get src operand into r11:\n");\r
- EaCalc (0,0x0007, sea,size,1);\r
- EaRead (0, 11, sea,size,0x0007,1);\r
+ EaCalc (0,0x0007, sea,size,earwt_shifted_up);\r
+ EaRead (0, 11, sea,size,0x0007,earwt_shifted_up);\r
\r
ot(";@ Get dst operand into r0:\n");\r
- EaCalcReadNoSE(-1,0,dea,size,0x0e00);\r
+ EaCalcRead(-1,0,dea,size,0x0e00,earwt_msb_dont_care);\r
\r
if (size<2) asl=(char *)(size?",asl #16":",asl #24");\r
\r
OpStart(op,ea); Cycles=10;\r
\r
ot(";@ Get value into r0:\n");\r
- EaCalcReadNoSE(-1,0,ea,size,0x003f);\r
+ EaCalcRead(-1,0,ea,size,0x003f,earwt_msb_dont_care);\r
\r
ot(";@ Get register operand into r1:\n");\r
- EaCalcReadNoSE(-1,1,rea,size,0x0e00);\r
+ EaCalcRead(-1,1,rea,size,0x0e00,earwt_msb_dont_care);\r
\r
if (size<2) ot(" mov r0,r0,asl #%d\n",size?16:24);\r
\r
\r
if(reg!=7) {\r
ot(";@ Get An\n");\r
- EaCalc(11, 7, 8, 2, 1);\r
- EaRead(11, 1, 8, 2, 7, 1);\r
+ EaCalc(11, 7, 8, 2);\r
+ EaRead(11, 1, 8, 2, 7);\r
}\r
\r
ot(" ldr r0,[r7,#0x3c] ;@ Get A7\n");\r
\r
ot(";@ Save to An\n");\r
if(reg!=7)\r
- EaWrite(11,8, 8, 2, 7, 1);\r
+ EaWrite(11, 8, 8, 2, 7);\r
\r
ot(";@ Get offset:\n");\r
EaCalc(0,0,0x3c,1); // abused r8 is ok because of imm EA\r
OpStart(op,0x10);\r
\r
ot(";@ Get An\n");\r
- EaCalc(11, 0xf, 8, 2, 1);\r
- EaRead(11, 0, 8, 2, 0xf, 1);\r
+ EaCalc(11, 0xf, 8, 2);\r
+ EaRead(11, 0, 8, 2, 0xf);\r
\r
ot(" add r8,r0,#4 ;@ A7+=4, abuse r8\n");\r
ot("\n");\r
ot(" str r8,[r7,#0x3c] ;@ Save A7\n");\r
ot("\n");\r
ot(";@ An = value from stack:\n");\r
- EaWrite(11, 0, 8, 2, 7, 1);\r
+ EaWrite(11, 0, 8, 2, 7);\r
\r
Cycles=12;\r
OpEnd(0x10);\r
if(size>=2) Cycles+=2;\r
}\r
\r
- EaCalcReadNoSE(-1,11,sea,0,0x0e00);\r
+ EaCalcRead(-1,11,sea,0,0x0e00,earwt_msb_dont_care);\r
\r
- EaCalcReadNoSE((type>0)?8:-1,0,tea,size,0x003f);\r
+ EaCalcRead((type>0)?8:-1,0,tea,size,0x003f,earwt_msb_dont_care);\r
\r
if (tea>=0x10)\r
ot(" and r11,r11,#7 ;@ mem - do mod 8\n"); // size always 0\r
if (type==2) ot(" bic r1,r0,r1,lsl r11 ;@ Clear bit\n");\r
if (type==3) ot(" orr r1,r0,r1,lsl r11 ;@ Set bit\n");\r
ot("\n");\r
- EaWrite(8,1,tea,size,0x003f,0,0);\r
+ EaWrite(8,1,tea,size,0x003f,earwt_msb_dont_care);\r
}\r
OpEnd(tea);\r
\r
OpStart(op,sea,tea);\r
\r
ot("\n");\r
- EaCalcReadNoSE(-1,0,sea,0,0);\r
+ EaCalcRead(-1,0,sea,0,0,earwt_msb_dont_care);\r
ot(" mov r11,#1\n");\r
ot(" bic r10,r10,#0x40000000 ;@ Blank Z flag\n");\r
if (tea>=0x10)\r
if(size>=2) Cycles+=2;\r
}\r
\r
- EaCalcReadNoSE((type>0)?8:-1,0,tea,size,0x003f);\r
+ EaCalcRead((type>0)?8:-1,0,tea,size,0x003f,earwt_msb_dont_care);\r
ot(" tst r0,r11 ;@ Do arithmetic\n");\r
ot(" orreq r10,r10,#0x40000000 ;@ Get Z flag\n");\r
ot("\n");\r
if (type==2) ot(" bic r1,r0,r11 ;@ Clear bit\n");\r
if (type==3) ot(" orr r1,r0,r11 ;@ Set bit\n");\r
ot("\n");\r
- EaWrite(8, 1,tea,size,0x003f,0,0);\r
+ EaWrite(8, 1,tea,size,0x003f,earwt_msb_dont_care);\r
#if CYCLONE_FOR_GENESIS && !MEMHANDLERS_CHANGE_CYCLES\r
// this is a bit hacky (device handlers might modify cycles)\r
if (tea==0x38||tea==0x39)\r
OpStart(op,ea); Cycles=size<2?4:6;\r
if(ea >= 0x10) Cycles*=2;\r
\r
- EaCalc (11,0x003f,ea,size,0,0);\r
+ EaCalc (11,0x003f,ea,size,earwt_msb_dont_care);\r
\r
- 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?)\r
+ 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?)\r
if (type==1) ot("\n");\r
\r
if (type==0)\r
}\r
\r
if (type==1) eawrite_check_addrerr=1;\r
- EaWrite(11, 1,ea,size,0x003f,0,0);\r
+ EaWrite(11, 1,ea,size,0x003f,earwt_msb_dont_care);\r
\r
OpEnd(ea);\r
\r
\r
OpStart(op); Cycles=4;\r
\r
- EaCalc (11,0x0007,ea,2,1);\r
- EaRead (11, 0,ea,2,0x0007,1);\r
+ EaCalc (11,0x0007,ea,2,earwt_shifted_up);\r
+ EaRead (11, 0,ea,2,0x0007,earwt_shifted_up);\r
\r
ot(" movs r1,r0,ror #16\n");\r
OpGetFlagsNZ(1);\r
\r
- EaWrite(11, 1,8,2,0x0007,1);\r
+ EaWrite(11, 1,8,2,0x0007,earwt_shifted_up);\r
\r
OpEnd();\r
\r
\r
OpStart(op,sea); Cycles=4;\r
\r
- EaCalc (0,0x003f,sea,size,1);\r
- EaRead (0, 0,sea,size,0x003f,1,0,1);\r
+ EaCalc (0,0x003f,sea,size,earwt_shifted_up);\r
+ EaRead (0, 0,sea,size,0x003f,earwt_shifted_up,1);\r
\r
OpGetFlagsNZ(0);\r
ot("\n");\r
\r
OpStart(op); Cycles=4;\r
\r
- EaCalc (11,0x0007,ea,size+1,0,0);\r
- EaRead (11, 0,ea,size+1,0x0007,0,0);\r
+ EaCalc (11,0x0007,ea,size+1,earwt_msb_dont_care);\r
+ EaRead (11, 0,ea,size+1,0x0007,earwt_msb_dont_care);\r
\r
ot(" movs r0,r0,asl #%d\n",shift);\r
OpGetFlagsNZ(0);\r
ot(" mov r1,r0,asr #%d\n",shift);\r
ot("\n");\r
\r
- EaWrite(11, 1,ea,size+1,0x0007,0,0);\r
+ EaWrite(11, 1,ea,size+1,0x0007,earwt_msb_dont_care);\r
\r
OpEnd();\r
return 0;\r
ot("\n");\r
\r
eawrite_check_addrerr=1;\r
- EaCalc (0,0x003f, ea,size,0,0);\r
- EaWrite(0, 1, ea,size,0x003f,0,0);\r
+ EaCalc (0,0x003f, ea,size,earwt_msb_dont_care);\r
+ EaWrite(0, 1, ea,size,0x003f,earwt_msb_dont_care);\r
\r
opend_op_changes_cycles=changed_cycles;\r
OpEnd(ea,0);\r
\r
OpStart(op,ea,0,count<0); Cycles=size<2?6:8;\r
\r
- EaCalc(11,0x0007, ea,size,1);\r
- EaRead(11, 0, ea,size,0x0007,1);\r
+ EaCalc(11,0x0007, ea,size,earwt_shifted_up);\r
+ EaRead(11, 0, ea,size,0x0007,earwt_shifted_up);\r
\r
EmitAsr(op,type,dir,count, size,usereg);\r
\r
- EaWrite(11, 0, ea,size,0x0007,1);\r
+ EaWrite(11, 0, ea,size,0x0007,earwt_shifted_up);\r
\r
opend_op_changes_cycles = (count<0);\r
OpEnd(ea,0);\r
\r
OpStart(op,ea); Cycles=6; // EmitAsr() will add 2\r
\r
- EaCalc (11,0x003f,ea,size,1);\r
- EaRead (11, 0,ea,size,0x003f,1);\r
+ EaCalc (11,0x003f,ea,size,earwt_shifted_up);\r
+ EaRead (11, 0,ea,size,0x003f,earwt_shifted_up);\r
\r
EmitAsr(op,type,dir,1,size,0);\r
\r
- EaWrite(11, 0,ea,size,0x003f,1);\r
+ EaWrite(11, 0,ea,size,0x003f,earwt_shifted_up);\r
\r
OpEnd(ea);\r
return 0;\r
Cycles=4;\r
if(ea>=8) Cycles+=10;\r
\r
- EaCalc (11,0x003f,ea,0,1);\r
- EaRead (11, 1,ea,0,0x003f,1,0,1);\r
+ EaCalc (11,0x003f,ea,0,earwt_shifted_up);\r
+ EaRead (11, 1,ea,0,0x003f,earwt_shifted_up,1);\r
\r
OpGetFlagsNZ(1);\r
ot("\n");\r
#endif\r
ot(" orr r1,r1,#0x80000000 ;@ set bit7\n");\r
\r
- EaWrite(11, 1,ea,0,0x003f,1);\r
+ EaWrite(11, 1,ea,0,0x003f,earwt_shifted_up);\r
#if CYCLONE_FOR_GENESIS\r
}\r
#endif\r
\r
if (movea==0)\r
{\r
- EaCalcRead(-1,1,sea,size,0x003f,1,1);\r
+ EaCalcRead(-1,1,sea,size,0x003f,earwt_sign_extend,1);\r
OpGetFlagsNZ(1);\r
ot("\n");\r
}\r
else\r
{\r
- EaCalcRead(-1,1,sea,size,0x003f);\r
+ EaCalcRead(-1,1,sea,size,0x003f,earwt_sign_extend);\r
size=2; // movea always expands to 32-bits\r
}\r
\r
eawrite_check_addrerr=1;\r
#if SPLIT_MOVEL_PD\r
if ((tea&0x38)==0x20 && size==2) { // -(An)\r
- EaCalc (8,0x0e00,tea,size,0,0);\r
+ EaCalc (8,0x0e00,tea,size,earwt_msb_dont_care);\r
ot(" mov r11,r1\n");\r
ot(" add r0,r8,#2\n");\r
- EaWrite(0, 1,tea,1,0x0e00,0,0);\r
- EaWrite(8, 11,tea,1,0x0e00,1);\r
+ EaWrite(0, 1,tea,1,0x0e00,earwt_msb_dont_care);\r
+ EaWrite(8, 11,tea,1,0x0e00,earwt_shifted_up);\r
}\r
else\r
#endif\r
{\r
- EaCalc (0,0x0e00,tea,size,0,0);\r
- EaWrite(0, 1,tea,size,0x0e00,0,0);\r
+ EaCalc (0,0x0e00,tea,size,earwt_msb_dont_care);\r
+ EaWrite(0, 1,tea,size,0x0e00,earwt_msb_dont_care);\r
}\r
\r
#if CYCLONE_FOR_GENESIS && !MEMHANDLERS_CHANGE_CYCLES\r
{\r
eawrite_check_addrerr=1;\r
OpFlagsToReg(type==0);\r
- EaCalc (0,0x003f,ea,size,0,0);\r
- EaWrite(0, 1,ea,size,0x003f,0,0);\r
+ EaCalc (0,0x003f,ea,size,earwt_msb_dont_care);\r
+ EaWrite(0, 1,ea,size,0x003f,earwt_msb_dont_care);\r
}\r
\r
if (type==2 || type==3)\r
{\r
- EaCalcReadNoSE(-1,0,ea,size,0x003f);\r
+ EaCalcRead(-1,0,ea,size,0x003f,earwt_msb_dont_care);\r
OpRegToFlags(type==3,1);\r
if (type==3) {\r
SuperChange(op,1);\r
\r
OpStart(op,ea,0,0,size!=0); Cycles=16;\r
\r
- EaCalcRead(-1,0,ea,size,0x003f);\r
+ EaCalcRead(-1,0,ea,size,0x003f,earwt_sign_extend);\r
\r
ot(" eor r1,r0,r0,ror #1 ;@ Bit 0=C^V\n");\r
ot(" tst r1,#1 ;@ 1 if C!=V\n");\r
#if SPLIT_MOVEL_PD\r
if (decr && size==2) { // -(An)\r
ot(" add r0,r6,#2\n");\r
- EaWrite(0,1,ea,1,0x003f,0,0);\r
+ EaWrite(0,1,ea,1,0x003f,earwt_msb_dont_care);\r
ot(" ldr r1,[r7,r4] ;@ Load value from Dn/An\n");\r
ot(" mov r0,r6\n");\r
- EaWrite(0,1,ea,1,0x003f,1);\r
+ EaWrite(0,1,ea,1,0x003f,earwt_shifted_up);\r
}\r
else\r
#endif\r
{\r
eawrite_check_addrerr=1;\r
ot(" ldr r1,[r7,#0x48] ;@ Get from USP\n\n");\r
- EaCalc (0,0x000f,8,2,1);\r
- EaWrite(0, 1,8,2,0x000f,1);\r
+ EaCalc (0,0x000f,8,2);\r
+ EaWrite(0, 1,8,2,0x000f);\r
}\r
else\r
{\r
- EaCalc (0,0x000f,8,2,1);\r
- EaRead (0, 0,8,2,0x000f,1);\r
+ EaCalc (0,0x000f,8,2);\r
+ EaRead (0, 0,8,2,0x000f);\r
ot(" str r0,[r7,#0x48] ;@ Put in USP\n\n");\r
}\r
\r
\r
if(dir) // reg to mem\r
{\r
- EaCalcReadNoSE(-1,11,rea,size,0x0e00);\r
+ EaCalcRead(-1,11,rea,size,0x0e00,earwt_msb_dont_care);\r
\r
EaCalc(8,0x000f,ea,size);\r
if(size==2) { // if operand is long\r
}\r
else // mem to reg\r
{\r
- EaCalc(6,0x000f,ea,size,1);\r
- EaRead(6,11,ea,0,0x000f,1); // read first byte\r
+ EaCalc(6,0x000f,ea,size,earwt_shifted_up);\r
+ EaRead(6,11,ea,0,0x000f,earwt_shifted_up); // read first byte\r
ot(" add r0,r6,#2\n");\r
- EaRead(0,1,ea,0,0x000f,1); // read second byte\r
+ EaRead(0,1,ea,0,0x000f,earwt_shifted_up); // read second byte\r
if(size==2) { // if operand is long\r
ot(" orr r11,r11,r1,lsr #8 ;@ second byte\n");\r
ot(" add r0,r6,#4\n");\r
- EaRead(0,1,ea,0,0x000f,1);\r
+ EaRead(0,1,ea,0,0x000f,earwt_shifted_up);\r
ot(" orr r11,r11,r1,lsr #16 ;@ third byte\n");\r
ot(" add r0,r6,#6\n");\r
- EaRead(0,1,ea,0,0x000f,1);\r
+ EaRead(0,1,ea,0,0x000f,earwt_shifted_up);\r
ot(" orr r1,r11,r1,lsr #24 ;@ fourth byte\n");\r
} else {\r
ot(" orr r1,r11,r1,lsr #8 ;@ second byte\n");\r
}\r
// store the result\r
- EaCalc(0,0x0e00,rea,size,1);\r
- EaWrite(0,1,rea,size,0x0e00,1);\r
+ EaCalc(0,0x0e00,rea,size,earwt_shifted_up);\r
+ EaWrite(0,1,rea,size,0x0e00,earwt_shifted_up);\r
ot(" ldr r6,[r7,#0x54]\n");\r
}\r
\r
#include "Disa/Disa.h"\r
\r
// Ea.cpp\r
+enum EaRWType {\r
+ earwt_sign_extend = 1,\r
+ earwt_zero_extend,\r
+ earwt_shifted_up,\r
+ earwt_msb_dont_care,\r
+};\r
+\r
extern int earead_check_addrerr;\r
extern int eawrite_check_addrerr;\r
extern int g_jmp_cycle_table[];\r
extern int g_pea_cycle_table[];\r
extern int g_movem_cycle_table[];\r
int Ea_add_ns(int *tab, int ea); // add nonstandard EA cycles\r
-int EaCalc(int a,int mask,int ea,int size,int top=0,int sign_extend=1); // 6\r
-int EaRead(int a,int v,int ea,int size,int mask,int top=0,int sign_extend=1,int set_nz=0); // 8\r
-int EaCalcRead(int r_ea,int r,int ea,int size,int mask,int sign_extend=1,int set_nz=0); // 7\r
-int EaCalcReadNoSE(int r_ea,int r,int ea,int size,int mask);\r
+int EaCalc(int a,int mask,int ea,int size,EaRWType type=earwt_sign_extend); // 6\r
+int EaRead(int a,int v,int ea,int size,int mask,EaRWType type=earwt_sign_extend,int set_nz=0); // 8\r
+int EaCalcRead(int r_ea,int r,int ea,int size,int mask,EaRWType type=earwt_sign_extend,int set_nz=0); // 7\r
int EaCanRead(int ea,int size);\r
-int EaWrite(int a,int v,int ea,int size,int mask,int top=0,int sign_extend_ea=1);\r
+int EaWrite(int a,int v,int ea,int size,int mask,EaRWType type=earwt_sign_extend);\r
int EaCanWrite(int ea);\r
int EaAn(int ea);\r
\r