X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=cyclone68000.git;a=blobdiff_plain;f=OpArith.cpp;h=96c7e0d7930457164166980ce24e0f531bb260a4;hp=ca279da6f5c625db6820b8769ba04cac8647305e;hb=HEAD;hpb=cfe17eee41a12da11f69660c2764813e94d871ea diff --git a/OpArith.cpp b/OpArith.cpp index ca279da..09517b8 100644 --- a/OpArith.cpp +++ b/OpArith.cpp @@ -37,33 +37,31 @@ 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); ot(";@ Do arithmetic:\n"); - if (type==0) ot(" orr r1,r10,r0%s\n",shiftstr); - if (type==1) ot(" and r1,r10,r0%s\n",shiftstr); + if (type==0) ot(" orrs r1,r10,r0%s\n",shiftstr); + if (type==1) ot(" ands r1,r10,r0%s\n",shiftstr); if (type==2||type==6) ot(" rsbs r1,r10,r0%s ;@ Defines NZCV\n",shiftstr); if (type==3) ot(" adds r1,r10,r0%s ;@ Defines NZCV\n",shiftstr); - if (type==5) ot(" eor r1,r10,r0%s\n",shiftstr); + if (type==5) ot(" eors r1,r10,r0%s\n",shiftstr); - if (type<2 || type==5) ot(" adds r1,r1,#0 ;@ Defines NZ, clears CV\n"); // 0,1,5 - - if (type< 2) OpGetFlags(0,0); // Ori/And + if (type< 2) OpGetFlagsNZ(1); // Ori/And if (type==2) OpGetFlags(1,1); // Sub: Subtract/X-bit if (type==3) OpGetFlags(0,1); // Add: X-bit - if (type==5) OpGetFlags(0,0); // Eor + if (type==5) OpGetFlagsNZ(1); // Eor if (type==6) OpGetFlags(1,0); // Cmp: Subtract ot("\n"); if (type!=6) { - EaWrite(11, 1, tea,size,0x003f,1); + EaWrite(11, 1, tea,size,0x003f,earwt_shifted_up); } // Correct cycles: @@ -114,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; @@ -243,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); @@ -327,9 +324,8 @@ int OpMul(int op) ot("\n"); } - ot(" mov r1,r3,lsl #16 ;@ Clip to 16-bits\n"); - ot(" adds r1,r1,#0 ;@ Defines NZ, clears CV\n"); - OpGetFlags(0,0); + ot(" movs r1,r3,lsl #16 ;@ Clip to 16-bits\n"); + OpGetFlagsNZ(1); ot(" mov r1,r1,lsr #16\n"); ot(" orr r1,r1,r2,lsl #16 ;@ Insert remainder\n"); @@ -343,13 +339,12 @@ int OpMul(int op) ot(" mov r2,r2,%s #16\n",sign?"asr":"lsr"); ot("\n"); - ot(" mul r1,r2,r0\n"); - ot(" adds r1,r1,#0 ;@ Defines NZ, clears CV\n"); - OpGetFlags(0,0); + ot(" muls r1,r2,r0\n"); + OpGetFlagsNZ(1); } 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); @@ -402,80 +397,73 @@ 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_msb_dont_care); + EaRead (0, 6, sea,0,0x000f,earwt_msb_dont_care); + 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); - ot(" mov r6,r6,asl #24\n"); + EaCalcRead(-1,6,sea,0,0x0007,earwt_msb_dont_care); + EaCalcRead(11,0,dea,0,0x0e00,earwt_msb_dont_care); } - ot(" mov r1,r0,asl #24\n\n"); ot(" bic r10,r10,#0xb1000000 ;@ clear all flags except old Z\n"); + ot(" ldr r1,[r7,#0x4c] ;@ Get X bit\n"); + ot(" and r2,r0,#0x0f\n"); + ot(" movs r12,r1,lsl #3 ;@ X into carry\n"); + ot(" and r1,r6,#0x0f\n"); if (type) { - ot(" ldr r0,[r7,#0x4c] ;@ Get X bit\n"); - ot(" mov r3,#0x00f00000\n"); - ot(" and r2,r3,r1,lsr #4\n"); - ot(" tst r0,#0x20000000\n"); - ot(" and r0,r3,r6,lsr #4\n"); - ot(" add r0,r0,r2\n"); - ot(" addne r0,r0,#0x00100000\n"); -// ot(" tst r0,#0x00800000\n"); -// ot(" orreq r10,r10,#0x01000000 ;@ Undefined V behavior\n"); - ot(" cmp r0,#0x00900000\n"); - ot(" addhi r0,r0,#0x00600000 ;@ Decimal adjust units\n"); - - ot(" mov r2,r1,lsr #28\n"); - ot(" add r0,r0,r2,lsl #24\n"); - ot(" mov r2,r6,lsr #28\n"); - ot(" add r0,r0,r2,lsl #24\n"); - ot(" cmp r0,#0x09900000\n"); + // abcd + ot(" adc r1,r2,r1\n"); + ot(" cmp r1,#9\n"); + + ot(" and r0,r0,#0xf0\n"); + ot(" and r6,r6,#0xf0\n"); + ot(" add r1,r1,r0\n"); + ot(" add r1,r1,r6\n"); + ot(" mov r12,r1\n"); + ot(" addhi r12,r12,#6 ;@ Decimal adjust units\n"); + ot(" tst r1,#0x80\n"); + ot(" orreq r10,r10,#0x10000000 ;@ Undefined V behavior\n"); + ot(" cmp r12,#0x9f\n"); ot(" orrhi r10,r10,#0x20000000 ;@ C\n"); - ot(" subhi r0,r0,#0x0a000000\n"); -// ot(" and r3,r10,r0,lsr #3 ;@ Undefined V behavior part II\n"); -// ot(" orr r10,r10,r3,lsl #4 ;@ V\n"); - ot(" movs r0,r0,lsl #4\n"); - ot(" orrmi r10,r10,#0x90000000 ;@ Undefined N+V behavior\n"); // this is what Musashi really does - ot(" bicne r10,r10,#0x40000000 ;@ Z flag\n"); + ot(" subhi r12,r12,#0xa0\n"); + ot(" movs r0,r12,lsl #24\n"); + ot(" bicpl r10,r10,#0x10000000 ;@ Undefined V behavior part II\n"); } else { - ot(" ldr r0,[r7,#0x4c] ;@ Get X bit\n"); - ot(" mov r3,#0x00f00000\n"); - ot(" and r2,r3,r6,lsr #4\n"); - ot(" tst r0,#0x20000000\n"); - ot(" and r0,r3,r1,lsr #4\n"); - ot(" sub r0,r0,r2\n"); - ot(" subne r0,r0,#0x00100000\n"); -// ot(" tst r0,#0x00800000\n"); -// ot(" orreq r10,r10,#0x01000000 ;@ Undefined V behavior\n"); - ot(" cmp r0,#0x00900000\n"); - ot(" subhi r0,r0,#0x00600000 ;@ Decimal adjust units\n"); - - ot(" mov r2,r1,lsr #28\n"); - ot(" add r0,r0,r2,lsl #24\n"); - ot(" mov r2,r6,lsr #28\n"); - ot(" sub r0,r0,r2,lsl #24\n"); - ot(" cmp r0,#0x09900000\n"); - ot(" orrhi r10,r10,#0xa0000000 ;@ N and C\n"); - ot(" addhi r0,r0,#0x0a000000\n"); -// ot(" and r3,r10,r0,lsr #3 ;@ Undefined V behavior part II\n"); -// ot(" orr r10,r10,r3,lsl #4 ;@ V\n"); - ot(" movs r0,r0,lsl #4\n"); -// ot(" orrmi r10,r10,#0x80000000 ;@ Undefined N behavior\n"); - ot(" bicne r10,r10,#0x40000000 ;@ Z flag\n"); + // sbcd + ot(" mov r12,#0 ;@ corf\n"); + ot(" adc r1,r1,#0\n"); + ot(" sub r1,r2,r1\n"); + ot(" cmp r1,#0x0f\n"); + ot(" movhi r12,#6\n"); + + ot(" and r0,r0,#0xf0\n"); + ot(" and r6,r6,#0xf0\n"); + ot(" add r1,r1,r0\n"); + ot(" sub r1,r1,r6\n"); + ot(" tst r1,#0x80\n"); + ot(" orrne r10,r10,#0x10000000 ;@ Undefined V behavior\n"); + ot(" cmp r1,r12\n"); + ot(" orrlt r10,r10,#0x20000000 ;@ C\n"); + ot(" cmp r1,#0xff\n"); + ot(" addhi r1,r1,#0xa0\n"); + ot(" sub r12,r1,r12\n"); + ot(" movs r0,r12,lsl #24\n"); + ot(" bicmi r10,r10,#0x10000000 ;@ Undefined V behavior part II\n"); } + ot(" orrmi r10,r10,#0x80000000 ;@ Undefined N behavior\n"); + ot(" bicne r10,r10,#0x40000000 ;@ Z flag\n"); 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); @@ -499,37 +487,34 @@ int OpNbcd(int op) OpStart(op,ea); Cycles=6; if(ea >= 8) Cycles+=2; - EaCalcReadNoSE(6,0,ea,0,0x003f); + EaCalcRead(11,0,ea,0,0x003f,earwt_zero_extend); // this is rewrite of Musashi's code ot(" ldr r2,[r7,#0x4c]\n"); ot(" bic r10,r10,#0xb0000000 ;@ clear all flags, except Z\n"); - ot(" mov r0,r0,asl #24\n"); ot(" and r2,r2,#0x20000000\n"); - ot(" add r2,r0,r2,lsr #5 ;@ add X\n"); - ot(" rsb r11,r2,#0x9a000000 ;@ do arithmetic\n"); + ot(" rsb r1,r0,#0 ;@ do arithmetic\n"); + ot(" subs r1,r1,r2,lsr #29 ;@ X\n"); - ot(" cmp r11,#0x9a000000\n"); ot(" beq finish%.4x\n",op); ot("\n"); - ot(" mvn r3,r11,lsr #31 ;@ Undefined V behavior\n",op); - ot(" and r2,r11,#0x0f000000\n"); - ot(" cmp r2,#0x0a000000\n"); - ot(" andeq r11,r11,#0xf0000000\n"); - ot(" addeq r11,r11,#0x10000000\n"); - ot(" and r3,r3,r11,lsr #31 ;@ Undefined V behavior part II\n",op); - ot(" movs r1,r11,asr #24\n"); + ot(" movs r1,r1,lsl #24\n"); + ot(" orrmi r10,r10,#0x10000000 ;@ Undefined V behavior\n"); + ot(" orr r2,r1,r0,lsl #24\n"); + ot(" tst r2,#0x0f000000\n"); + ot(" andeq r1,r1,#0xf0000000\n"); + ot(" orreq r1,r1,#0x06000000\n"); + ot(" adds r1,r1,#0x9a000000\n"); + ot(" bicmi r10,r10,#0x10000000 ;@ Undefined V behavior part II\n"); + ot(" orrmi r10,r10,#0x80000000 ;@ Undefined N behavior\n"); ot(" bicne r10,r10,#0x40000000 ;@ Z\n"); - ot(" orr r10,r10,r3,lsl #28 ;@ save V\n",op); ot(" orr r10,r10,#0x20000000 ;@ C\n"); ot("\n"); - EaWrite(6, 1, ea,0,0x3f,0,0); + EaWrite(11, 1, ea,0,0x3f,earwt_shifted_up); ot("finish%.4x%s\n",op,ms?"":":"); - ot(" tst r11,r11\n"); - ot(" orrmi r10,r10,#0x80000000 ;@ N\n"); ot(" str r10,[r7,#0x4c] ;@ Save X\n"); ot("\n"); @@ -569,14 +554,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 @@ -628,15 +613,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); } @@ -665,7 +650,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); @@ -707,26 +692,28 @@ 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"); ot(";@ Do arithmetic:\n"); - if (eor==0) ot(" rsbs r1,r0,r1%s\n",asl); if (eor) { - ot(" eor r1,r0,r1%s\n",asl); - ot(" adds r1,r1,#0 ;@ Defines NZ, clears CV\n"); + ot(" eors r1,r0,r1%s\n",asl); + OpGetFlagsNZ(1); + } + else + { + ot(" rsbs r1,r0,r1%s\n",asl); + OpGetFlags(1,0); // Cmp like subtract } - - OpGetFlags(eor==0,0); // Cmp like subtract 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; @@ -751,11 +738,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"); @@ -794,24 +781,24 @@ 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); - if (size<2) ot(" mov r1,r1,asl #%d\n\n",size?16:24); + + if (size<2) ot(" movs r1,r1,asl #%d\n\n",size?16:24); + else ot(" adds r1,r1,#0 ;@ Define flags\n"); ot(";@ get flags, including undocumented ones\n"); ot(" and r3,r10,#0x80000000\n"); - ot(" adds r1,r1,#0 ;@ Defines NZ, clears CV\n"); - OpGetFlags(0,0); + OpGetFlagsNZ(1); ot(";@ is reg negative?\n"); ot(" bmi chktrap%.4x\n",op); ot(";@ Do arithmetic:\n"); - ot(" bic r10,r10,#0x80000000 ;@ N\n"); ot(" cmp r1,r0\n"); ot(" bgt chktrap%.4x\n",op); @@ -828,3 +815,4 @@ int OpChk(int op) return 0; } +// vim:ts=2:sw=2:expandtab