X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=cpu%2FCyclone%2FOpLogic.cpp;h=4bd0869569c4a281995c7c44af9a6f4e3e173cd3;hb=0e11c502b05a9ccd67d34d1f0975852d8c3d4232;hp=d0eafecfd16b510f8579329aaa38a9cc88113e00;hpb=c008977e8ec74b68cbccc017620a156cc39b79b2;p=picodrive.git diff --git a/cpu/Cyclone/OpLogic.cpp b/cpu/Cyclone/OpLogic.cpp index d0eafec..4bd0869 100644 --- a/cpu/Cyclone/OpLogic.cpp +++ b/cpu/Cyclone/OpLogic.cpp @@ -23,11 +23,11 @@ int OpBtstReg(int op) if (EaCanWrite(tea)==0) return 1; } - use=OpBase(op); + use=OpBase(op,size); use&=~0x0e00; // Use same handler for all registers if (op!=use) { OpUse(op,use); return 0; } // Use existing handler - OpStart(op); + OpStart(op,tea); if(type==1||type==3) { Cycles=8; @@ -36,15 +36,15 @@ int OpBtstReg(int op) if(size>=2) Cycles+=2; } - EaCalc (0,0x0e00,sea,0); - EaRead (0, 0,sea,0,0x0e00); + EaCalcReadNoSE(-1,10,sea,0,0x0e00); + + EaCalcReadNoSE((type>0)?11:-1,0,tea,size,0x003f); + if (tea>=0x10) - ot(" and r10,r0,#7 ;@ mem - do mod 8\n"); - else ot(" and r10,r0,#31 ;@ reg - do mod 32\n"); + ot(" and r10,r10,#7 ;@ mem - do mod 8\n"); // size always 0 + else ot(" and r10,r10,#31 ;@ reg - do mod 32\n"); // size always 2 ot("\n"); - EaCalc(11,0x003f,tea,size); - EaRead(11, 0,tea,size,0x003f); ot(" mov r1,#1\n"); ot(" tst r0,r1,lsl r10 ;@ Do arithmetic\n"); ot(" bicne r9,r9,#0x40000000\n"); @@ -57,9 +57,9 @@ int OpBtstReg(int op) if (type==2) ot(" bic r1,r0,r1,lsl r10 ;@ Clear bit\n"); if (type==3) ot(" orr r1,r0,r1,lsl r10 ;@ Set bit\n"); ot("\n"); - EaWrite(11, 1,tea,size,0x003f); + EaWrite(11, 1,tea,size,0x003f,0,0); } - OpEnd(); + OpEnd(tea); return 0; } @@ -85,19 +85,18 @@ int OpBtstImm(int op) if (EaCanWrite(tea)==0) return 1; } - use=OpBase(op); + use=OpBase(op,size); if (op!=use) { OpUse(op,use); return 0; } // Use existing handler - OpStart(op); + OpStart(op,sea,tea); - ot(" mov r10,#1\n"); ot("\n"); - EaCalc ( 0,0x0000,sea,0); - EaRead ( 0, 0,sea,0,0); + EaCalcReadNoSE(-1,0,sea,0,0); + ot(" mov r10,#1\n"); ot(" bic r9,r9,#0x40000000 ;@ Blank Z flag\n"); if (tea>=0x10) - ot(" and r0,r0,#7 ;@ mem - do mod 8\n"); - else ot(" and r0,r0,#0x1F ;@ reg - do mod 32\n"); + ot(" and r0,r0,#7 ;@ mem - do mod 8\n"); // size always 0 + else ot(" and r0,r0,#0x1F ;@ reg - do mod 32\n"); // size always 2 ot(" mov r10,r10,lsl r0 ;@ Make bit mask\n"); ot("\n"); @@ -108,8 +107,7 @@ int OpBtstImm(int op) if(size>=2) Cycles+=2; } - EaCalc (11,0x003f,tea,size); - EaRead (11, 0,tea,size,0x003f); + EaCalcReadNoSE((type>0)?11:-1,0,tea,size,0x003f); ot(" tst r0,r10 ;@ Do arithmetic\n"); ot(" orreq r9,r9,#0x40000000 ;@ Get Z flag\n"); ot("\n"); @@ -120,10 +118,10 @@ int OpBtstImm(int op) if (type==2) ot(" bic r1,r0,r10 ;@ Clear bit\n"); if (type==3) ot(" orr r1,r0,r10 ;@ Set bit\n"); ot("\n"); - EaWrite(11, 1,tea,size,0x003f); + EaWrite(11, 1,tea,size,0x003f,0,0); } - OpEnd(); + OpEnd(sea,tea); return 0; } @@ -142,13 +140,13 @@ int OpNeg(int op) if (EaCanRead (ea,size)==0||EaAn(ea)) return 1; if (EaCanWrite(ea )==0) return 1; - use=OpBase(op); + use=OpBase(op,size); if (op!=use) { OpUse(op,use); return 0; } // Use existing handler - OpStart(op); Cycles=size<2?4:6; + OpStart(op,ea); Cycles=size<2?4:6; if(ea >= 0x10) { Cycles*=2; -#ifdef CYCLONE_FOR_GENESIS +#if CYCLONE_FOR_GENESIS // This is same as in Starscream core, CLR uses only 6 cycles for memory EAs. // May be this is similar case as with TAS opcode, but this time the dummy // read is ignored somehow? Without this hack Fatal Rewind hangs even in Gens. @@ -156,24 +154,24 @@ int OpNeg(int op) #endif } - EaCalc (10,0x003f,ea,size); + EaCalc (10,0x003f,ea,size,0,0); - if (type!=1) EaRead (10,0,ea,size,0x003f); // Don't need to read for 'clr' + if (type!=1) EaRead (10,0,ea,size,0x003f,0,0); // Don't need to read for 'clr' (or do we, for a dummy read?) if (type==1) ot("\n"); if (type==0) { ot(";@ Negx:\n"); GetXBit(1); - if(size!=2) ot(" mov r0,r0,lsl #%i\n",size?16:24); + if(size!=2) ot(" mov r0,r0,asl #%i\n",size?16:24); ot(" rscs r1,r0,#0 ;@ do arithmetic\n"); ot(" orr r3,r9,#0xb0000000 ;@ for old Z\n"); OpGetFlags(1,1,0); if(size!=2) { - ot(" movs r1,r1,asr #%i\n",size?16:24); + ot(" movs r1,r1,asr #%i\n",size?16:24); ot(" orreq r9,r9,#0x40000000 ;@ possily missed Z\n"); - } - ot(" andeq r9,r9,r3 ;@ fix Z\n"); + } + ot(" andeq r9,r9,r3 ;@ fix Z\n"); ot("\n"); } @@ -188,7 +186,7 @@ int OpNeg(int op) if (type==2) { ot(";@ Neg:\n"); - if(size!=2) ot(" mov r0,r0,lsl #%i\n",size?16:24); + if(size!=2) ot(" mov r0,r0,asl #%i\n",size?16:24); ot(" rsbs r1,r0,#0\n"); OpGetFlags(1,1); if(size!=2) ot(" mov r1,r1,asr #%i\n",size?16:24); @@ -198,15 +196,21 @@ int OpNeg(int op) if (type==3) { ot(";@ Not:\n"); - ot(" mvn r1,r0\n"); + if(size!=2) { + ot(" mov r0,r0,asl #%i\n",size?16:24); + ot(" mvn r1,r0,asr #%i\n",size?16:24); + } + else + ot(" mvn r1,r0\n"); ot(" adds r1,r1,#0 ;@ Defines NZ, clears CV\n"); OpGetFlags(0,0); ot("\n"); } - EaWrite(10, 1,ea,size,0x003f); + if (type==1) eawrite_check_addrerr=1; + EaWrite(10, 1,ea,size,0x003f,0,0); - OpEnd(); + OpEnd(ea); return 0; } @@ -251,10 +255,10 @@ int OpTst(int op) // See if we can do this opcode: if (EaCanWrite(sea)==0||EaAn(sea)) return 1; - use=OpBase(op); + use=OpBase(op,size); if (op!=use) { OpUse(op,use); return 0; } // Use existing handler - OpStart(op); Cycles=4; + OpStart(op,sea); Cycles=4; EaCalc ( 0,0x003f,sea,size,1); EaRead ( 0, 0,sea,size,0x003f,1); @@ -263,7 +267,7 @@ int OpTst(int op) ot(" mrs r9,cpsr ;@ r9=flags\n"); ot("\n"); - OpEnd(); + OpEnd(sea); return 0; } @@ -279,13 +283,13 @@ int OpExt(int op) size=(op>>6)&1; shift=32-(8<=2; + OpStart(op,ea,0,changed_cycles); Cycles=8; if (ea<8) Cycles=4; - ot(" mov r1,#0\n"); + if (cc) + ot(" mov r1,#0\n"); - if (cc!=1) + switch (cc) { - ot(";@ Is the condition true?\n"); - if ((cc&~1)==2) ot(" eor r9,r9,#0x20000000 ;@ Invert carry for hi/ls\n"); - ot(" msr cpsr_flg,r9 ;@ ARM flags = 68000 flags\n"); - if ((cc&~1)==2) ot(" eor r9,r9,#0x20000000 ;@ Invert carry for hi/ls\n"); - ot(" mvn%s r1,r1\n",cond[cc]); + case 0: // T + ot(" mvn r1,#0\n"); + if (ea<8) Cycles+=2; + break; + case 1: // F + break; + case 2: // hi + ot(" tst r9,#0x60000000 ;@ hi: !C && !Z\n"); + ot(" mvneq r1,r1\n"); + if (ea<8) ot(" subeq r5,r5,#2 ;@ Extra cycles\n"); + break; + case 3: // ls + ot(" tst r9,#0x60000000 ;@ ls: C || Z\n"); + ot(" mvnne r1,r1\n"); + if (ea<8) ot(" subne r5,r5,#2 ;@ Extra cycles\n"); + break; + default: + ot(";@ Is the condition true?\n"); + ot(" msr cpsr_flg,r9 ;@ ARM flags = 68000 flags\n"); + ot(" mvn%s r1,r1\n",cond[cc]); + if (ea<8) ot(" sub%s r5,r5,#2 ;@ Extra cycles\n",cond[cc]); + break; } - if (cc!=1 && ea<8) ot(" sub%s r5,r5,#2 ;@ Extra cycles\n",cond[cc]); ot("\n"); - EaCalc (0,0x003f, ea,size); - EaWrite(0, 1, ea,size,0x003f); + eawrite_check_addrerr=1; + EaCalc (0,0x003f, ea,size,0,0); + EaWrite(0, 1, ea,size,0x003f,0,0); - OpEnd(); + opend_op_changes_cycles=changed_cycles; + OpEnd(ea,0); return 0; } @@ -357,7 +381,7 @@ static int EmitAsr(int op,int type,int dir,int count,int size,int usereg) if (usereg) { ot(";@ Use Dn for count:\n"); - ot(" and r2,r8,#7<<9\n"); + ot(" and r2,r8,#0x0e00\n"); ot(" ldr r2,[r7,r2,lsr #7]\n"); ot(" and r2,r2,#63\n"); ot("\n"); @@ -383,29 +407,30 @@ static int EmitAsr(int op,int type,int dir,int count,int size,int usereg) ot("\n"); } - if (type==0 && dir) ot(" mov r3,r0 ;@ save old value for V flag calculation\n"); + if (type==0 && dir) ot(" adds r3,r0,#0 ;@ save old value for V flag calculation, also clear V\n"); ot(";@ Shift register:\n"); if (type==0) ot(" movs r0,r0,%s %s\n",dir?"asl":"asr",pct); if (type==1) ot(" movs r0,r0,%s %s\n",dir?"lsl":"lsr",pct); - if (dir==0 && size<2) - { - ot(";@ restore after right shift:\n"); - ot(" mov r0,r0,lsl #%d\n",32-(8<>9)&7; dir =(op>>8)&1; size =(op>>6)&3; @@ -582,13 +602,13 @@ int OpAsr(int op) // Use the same opcode for target registers: use=op&~0x0007; - // As long as count is not 8, use the same opcode for all shift counts:: + // As long as count is not 8, use the same opcode for all shift counts: if (usereg==0 && count!=8 && !(count==1&&type==2)) { use|=0x0e00; count=-1; } if (usereg) { use&=~0x0e00; count=-1; } // Use same opcode for all Dn if (op!=use) { OpUse(op,use); return 0; } // Use existing handler - OpStart(op); Cycles=size<2?6:8; + OpStart(op,ea,0,count<0); Cycles=size<2?6:8; EaCalc(10,0x0007, ea,size,1); EaRead(10, 0, ea,size,0x0007,1); @@ -597,7 +617,8 @@ int OpAsr(int op) EaWrite(10, 0, ea,size,0x0007,1); - OpEnd(); + opend_op_changes_cycles = (count<0); + OpEnd(ea,0); return 0; } @@ -616,10 +637,10 @@ int OpAsrEa(int op) if (EaCanRead(ea,0)==0) return 1; if (EaCanWrite(ea)==0) return 1; - use=OpBase(op); + use=OpBase(op,size); if (op!=use) { OpUse(op,use); return 0; } // Use existing handler - OpStart(op); Cycles=6; // EmitAsr() will add 2 + OpStart(op,ea); Cycles=6; // EmitAsr() will add 2 EaCalc (10,0x003f,ea,size,1); EaRead (10, 0,ea,size,0x003f,1); @@ -628,7 +649,7 @@ int OpAsrEa(int op) EaWrite(10, 0,ea,size,0x003f,1); - OpEnd(); + OpEnd(ea); return 0; } @@ -642,10 +663,10 @@ int OpTas(int op, int gen_special) // See if we can do this opcode: if (EaCanWrite(ea)==0 || EaAn(ea)) return 1; - use=OpBase(op); + use=OpBase(op,0); if (op!=use) { OpUse(op,use); return 0; } // Use existing handler - if (!gen_special) OpStart(op); + if (!gen_special) OpStart(op,ea); else ot("Op%.4x_%s\n", op, ms?"":":"); @@ -670,9 +691,9 @@ int OpTas(int op, int gen_special) } #endif - OpEnd(); + OpEnd(ea); -#if CYCLONE_FOR_GENESIS +#if (CYCLONE_FOR_GENESIS == 2) if (!gen_special && ea >= 0x10) { OpTas(op, 1); }