4 // --------------------- Opcodes 0x0000+ ---------------------
\r
5 // Emit an Ori/And/Sub/Add/Eor/Cmp Immediate opcode, 0000ttt0 ssaaaaaa
\r
11 const char *shiftstr="";
\r
13 // Get source and target EA
\r
14 type=(op>>9)&7; if (type==4 || type>=7) return 1;
\r
15 size=(op>>6)&3; if (size>=3) return 1;
\r
19 // See if we can do this opcode:
\r
20 if (EaCanRead(tea,size)==0) return 1;
\r
21 if (EaCanWrite(tea)==0 || EaAn(tea)) return 1;
\r
23 use=OpBase(op,size);
\r
24 if (op!=use) { OpUse(op,use); return 0; } // Use existing handler
\r
26 OpStart(op, sea, tea); Cycles=4;
\r
28 // imm must be read first
\r
29 EaCalcReadNoSE(-1,10,sea,size,0);
\r
30 EaCalcReadNoSE((type!=6)?11:-1,0,tea,size,0x003f);
\r
32 if (size<2) shiftstr=(char *)(size?",asl #16":",asl #24");
\r
33 if (size<2) ot(" mov r10,r10,asl #%i\n",size?16:24);
\r
35 ot(";@ Do arithmetic:\n");
\r
37 if (type==0) ot(" orr r1,r10,r0%s\n",shiftstr);
\r
38 if (type==1) ot(" and r1,r10,r0%s\n",shiftstr);
\r
39 if (type==2||type==6)
\r
40 ot(" rsbs r1,r10,r0%s ;@ Defines NZCV\n",shiftstr);
\r
41 if (type==3) ot(" adds r1,r10,r0%s ;@ Defines NZCV\n",shiftstr);
\r
42 if (type==5) ot(" eor r1,r10,r0%s\n",shiftstr);
\r
44 if (type<2 || type==5) ot(" adds r1,r1,#0 ;@ Defines NZ, clears CV\n"); // 0,1,5
\r
46 if (type< 2) OpGetFlags(0,0); // Ori/And
\r
47 if (type==2) OpGetFlags(1,1); // Sub: Subtract/X-bit
\r
48 if (type==3) OpGetFlags(0,1); // Add: X-bit
\r
49 if (type==5) OpGetFlags(0,0); // Eor
\r
50 if (type==6) OpGetFlags(1,0); // Cmp: Subtract
\r
55 EaWrite(11, 1, tea,size,0x003f,1);
\r
61 if (size>=2 && tea<0x10) Cycles+=2;
\r
65 if (size>=2) Cycles+=4;
\r
66 if (tea>=8) Cycles+=4;
\r
67 if (type==1 && size>=2 && tea<8) Cycles-=2;
\r
75 // --------------------- Opcodes 0x5000+ ---------------------
\r
78 // 0101nnnt xxeeeeee (nnn=#8,1-7 t=addq/subq xx=size, eeeeee=EA)
\r
79 int num=0,type=0,size=0,ea=0;
\r
84 num =(op>>9)&7; if (num==0) num=8;
\r
86 size=(op>>6)&3; if (size>=3) return 1;
\r
89 // See if we can do this opcode:
\r
90 if (EaCanRead (ea,size)==0) return 1;
\r
91 if (EaCanWrite(ea) ==0) return 1;
\r
92 if (size == 0 && EaAn(ea) ) return 1;
\r
94 use=OpBase(op,size,1);
\r
96 if (num!=8) use|=0x0e00; // If num is not 8, use same handler
\r
97 if (op!=use) { OpUse(op,use); return 0; } // Use existing handler
\r
101 if(type==0&&size==1) Cycles=ea<0x10?4:8;
\r
102 if(size>=2) Cycles=ea<0x10?8:12;
\r
104 if (size>0 && (ea&0x38)==0x08) size=2; // addq.w #n,An is also 32-bit
\r
106 EaCalcReadNoSE(11,0,ea,size,0x003f);
\r
108 shift=32-(8<<size);
\r
114 ot(" and r2,r8,#0x0e00 ;@ Get quick value\n");
\r
116 if (lsr>=0) sprintf(count,"r2,lsr #%d", lsr);
\r
117 else sprintf(count,"r2,lsl #%d", -lsr);
\r
123 sprintf(count,"#0x%.4x",8<<shift);
\r
126 if (size<2) ot(" mov r0,r0,asl #%d\n\n",size?16:24);
\r
128 if (type==0) ot(" adds r1,r0,%s\n",count);
\r
129 if (type==1) ot(" subs r1,r0,%s\n",count);
\r
131 if ((ea&0x38)!=0x08) OpGetFlags(type,1);
\r
134 EaWrite(11, 1, ea,size,0x003f,1);
\r
141 // --------------------- Opcodes 0x8000+ ---------------------
\r
142 // 1t0tnnnd xxeeeeee (tt=type:or/sub/and/add xx=size, eeeeee=EA)
\r
143 int OpArithReg(int op)
\r
146 int type=0,size=0,dir=0,rea=0,ea=0;
\r
147 const char *asl="";
\r
148 const char *strop=0;
\r
152 dir =(op>> 8)&1; // er,re
\r
153 size=(op>> 6)&3; if (size>=3) return 1;
\r
156 if (dir && ea<0x10) return 1; // addx/subx opcode
\r
158 // See if we can do this opcode:
\r
159 if (dir==0 && EaCanRead (ea,size)==0) return 1;
\r
160 if (dir && EaCanWrite(ea)==0) return 1;
\r
161 if ((size==0||!(type&1))&&EaAn(ea)) return 1;
\r
163 use=OpBase(op,size);
\r
164 use&=~0x0e00; // Use same opcode for Dn
\r
165 if (op!=use) { OpUse(op,use); return 0; } // Use existing handler
\r
167 OpStart(op,ea); Cycles=4;
\r
169 EaCalcReadNoSE(dir?11:-1,0,ea,size,0x003f);
\r
171 EaCalcReadNoSE(dir?-1:11,1,rea,size,0x0e00);
\r
173 ot(";@ Do arithmetic:\n");
\r
174 if (type==0) strop = "orr";
\r
175 if (type==1) strop = (char *) (dir ? "subs" : "rsbs");
\r
176 if (type==4) strop = "and";
\r
177 if (type==5) strop = "adds";
\r
179 if (size==0) asl=",asl #24";
\r
180 if (size==1) asl=",asl #16";
\r
182 if (size<2) ot(" mov r0,r0%s\n",asl);
\r
183 ot(" %s r1,r0,r1%s\n",strop,asl);
\r
185 if ((type&1)==0) ot(" adds r1,r1,#0 ;@ Defines NZ, clears CV\n");
\r
187 OpGetFlags(type==1,type&1); // 1==subtract
\r
190 ot(";@ Save result:\n");
\r
191 if (size<2) ot(" mov r1,r1,asr #%d\n",size?16:24);
\r
192 if (dir) EaWrite(11, 1, ea,size,0x003f,0,0);
\r
193 else EaWrite(11, 1,rea,size,0x0e00,0,0);
\r
196 if(ea<8) Cycles=(size>=2)?8:4; else Cycles+=(size>=2)?26:14;
\r
199 if(size>=2) Cycles+=4;
\r
203 if(ea<0x10||ea==0x3c) Cycles+=2;
\r
212 // --------------------- Opcodes 0x80c0+ ---------------------
\r
215 // Div/Mul: 1m00nnns 11eeeeee (m=Mul, nnn=Register Dn, s=signed, eeeeee=EA)
\r
216 int type=0,rea=0,sign=0,ea=0;
\r
219 type=(op>>14)&1; // div/mul
\r
224 // See if we can do this opcode:
\r
225 if (EaCanRead(ea,1)==0||EaAn(ea)) return 1;
\r
228 use&=~0x0e00; // Use same for all registers
\r
229 if (op!=use) { OpUse(op,use); return 0; } // Use existing handler
\r
232 if(type) Cycles=54;
\r
233 else Cycles=sign?158:140;
\r
235 EaCalcReadNoSE(-1,0,ea,1,0x003f);
\r
237 EaCalc(11,0x0e00,rea, 2);
\r
238 EaRead(11, 2,rea, 2,0x0e00);
\r
240 ot(" movs r1,r0,asl #16\n");
\r
242 if (type==0) // div
\r
244 // the manual says C is always cleared, but neither Musashi nor FAME do that
\r
245 //ot(" bic r10,r10,#0x20000000 ;@ always clear C\n");
\r
246 ot(" beq divzero%.4x ;@ division by zero\n",op);
\r
251 ot(" mov r12,#0 ;@ r12 = 1 or 2 if the result is negative\n");
\r
252 ot(" tst r2,r2\n");
\r
253 ot(" orrmi r12,r12,#2\n");
\r
254 ot(" rsbmi r2,r2,#0 ;@ Make r2 positive\n");
\r
256 ot(" movs r0,r1,asr #16\n");
\r
257 ot(" orrmi r12,r12,#1\n");
\r
258 ot(" rsbmi r0,r0,#0 ;@ Make r0 positive\n");
\r
260 ot(";@ detect the nasty 0x80000000 / -1 situation\n");
\r
261 ot(" mov r3,r2,asr #31\n");
\r
262 ot(" eors r3,r3,r1,asr #16\n");
\r
263 ot(" beq wrendofop%.4x\n",op);
\r
267 ot(" mov r0,r1,lsr #16 ;@ use only 16 bits of divisor\n");
\r
271 ot(";@ Divide r2 by r0\n");
\r
272 ot(" mov r3,#0\n");
\r
273 ot(" mov r1,r0\n");
\r
275 ot(";@ Shift up divisor till it's just less than numerator\n");
\r
276 ot("Shift%.4x%s\n",op,ms?"":":");
\r
277 ot(" cmp r1,r2,lsr #1\n");
\r
278 ot(" movls r1,r1,lsl #1\n");
\r
279 ot(" bcc Shift%.4x\n",op);
\r
282 ot("Divide%.4x%s\n",op,ms?"":":");
\r
283 ot(" cmp r2,r1\n");
\r
284 ot(" adc r3,r3,r3 ;@ Double r3 and add 1 if carry set\n");
\r
285 ot(" subcs r2,r2,r1\n");
\r
286 ot(" teq r1,r0\n");
\r
287 ot(" movne r1,r1,lsr #1\n");
\r
288 ot(" bne Divide%.4x\n",op);
\r
290 ot(";@r3==quotient,r2==remainder\n");
\r
295 ot(" and r1,r12,#1\n");
\r
296 ot(" teq r1,r12,lsr #1\n");
\r
297 ot(" rsbne r3,r3,#0 ;@ negate if quotient is negative\n");
\r
298 ot(" tst r12,#2\n");
\r
299 ot(" rsbne r2,r2,#0 ;@ negate the remainder if divident was negative\n");
\r
302 // signed overflow check
\r
303 ot(" mov r1,r3,asl #16\n");
\r
304 ot(" cmp r3,r1,asr #16 ;@ signed overflow?\n");
\r
305 ot(" orrne r10,r10,#0x10000000 ;@ set overflow flag\n");
\r
306 ot(" bne endofop%.4x ;@ overflow!\n",op);
\r
308 ot("wrendofop%.4x%s\n",op,ms?"":":");
\r
313 ot(" movs r1,r3,lsr #16 ;@ check for overflow condition\n");
\r
314 ot(" orrne r10,r10,#0x10000000 ;@ set overflow flag\n");
\r
315 ot(" bne endofop%.4x ;@ overflow!\n",op);
\r
319 ot(" mov r1,r3,lsl #16 ;@ Clip to 16-bits\n");
\r
320 ot(" adds r1,r1,#0 ;@ Defines NZ, clears CV\n");
\r
323 ot(" mov r1,r1,lsr #16\n");
\r
324 ot(" orr r1,r1,r2,lsl #16 ;@ Insert remainder\n");
\r
329 ot(";@ Get 16-bit signs right:\n");
\r
330 ot(" mov r0,r1,%s #16\n",sign?"asr":"lsr");
\r
331 ot(" mov r2,r2,lsl #16\n");
\r
332 ot(" mov r2,r2,%s #16\n",sign?"asr":"lsr");
\r
335 ot(" mul r1,r2,r0\n");
\r
336 ot(" adds r1,r1,#0 ;@ Defines NZ, clears CV\n");
\r
341 EaWrite(11, 1,rea, 2,0x0e00,1);
\r
343 if (type==0) ot("endofop%.4x%s\n",op,ms?"":":");
\r
346 if (type==0) // div
\r
348 ot("divzero%.4x%s\n",op,ms?"":":");
\r
349 ot(" mov r0,#5 ;@ Divide by zero\n");
\r
350 ot(" bl Exception\n");
\r
359 // Get X Bit into carry - trashes r2
\r
360 int GetXBit(int subtract)
\r
362 ot(";@ Get X bit:\n");
\r
363 ot(" ldr r2,[r7,#0x4c]\n");
\r
364 if (subtract) ot(" mvn r2,r2 ;@ Invert it\n");
\r
365 ot(" msr cpsr_flg,r2 ;@ Get into Carry\n");
\r
370 // --------------------- Opcodes 0x8100+ ---------------------
\r
371 // 1t00ddd1 0000asss - sbcd/abcd Ds,Dd or -(As),-(Ad)
\r
375 int type=0,sea=0,mem=0,dea=0;
\r
377 type=(op>>14)&1; // sbcd/abcd
\r
382 if (mem) { sea|=0x20; dea|=0x20; }
\r
384 use=op&~0x0e07; // Use same opcode for all registers..
\r
385 if (sea==0x27) use|=0x0007; // ___x.b -(a7)
\r
386 if (dea==0x27) use|=0x0e00; // ___x.b -(a7)
\r
387 if (op!=use) { OpUse(op,use); return 0; } // Use existing handler
\r
389 OpStart(op,sea,dea); Cycles=6;
\r
393 ot(";@ Get src/dest EA vals\n");
\r
394 EaCalc (0,0x000f, sea,0,1);
\r
395 EaRead (0, 6, sea,0,0x000f,1);
\r
396 EaCalcReadNoSE(11,0,dea,0,0x0e00);
\r
400 ot(";@ Get src/dest reg vals\n");
\r
401 EaCalcReadNoSE(-1,6,sea,0,0x0007);
\r
402 EaCalcReadNoSE(11,0,dea,0,0x0e00);
\r
403 ot(" mov r6,r6,asl #24\n");
\r
405 ot(" mov r1,r0,asl #24\n\n");
\r
407 ot(" bic r10,r10,#0xb1000000 ;@ clear all flags except old Z\n");
\r
411 ot(" ldr r0,[r7,#0x4c] ;@ Get X bit\n");
\r
412 ot(" mov r3,#0x00f00000\n");
\r
413 ot(" and r2,r3,r1,lsr #4\n");
\r
414 ot(" tst r0,#0x20000000\n");
\r
415 ot(" and r0,r3,r6,lsr #4\n");
\r
416 ot(" add r0,r0,r2\n");
\r
417 ot(" addne r0,r0,#0x00100000\n");
\r
418 // ot(" tst r0,#0x00800000\n");
\r
419 // ot(" orreq r10,r10,#0x01000000 ;@ Undefined V behavior\n");
\r
420 ot(" cmp r0,#0x00900000\n");
\r
421 ot(" addhi r0,r0,#0x00600000 ;@ Decimal adjust units\n");
\r
423 ot(" mov r2,r1,lsr #28\n");
\r
424 ot(" add r0,r0,r2,lsl #24\n");
\r
425 ot(" mov r2,r6,lsr #28\n");
\r
426 ot(" add r0,r0,r2,lsl #24\n");
\r
427 ot(" cmp r0,#0x09900000\n");
\r
428 ot(" orrhi r10,r10,#0x20000000 ;@ C\n");
\r
429 ot(" subhi r0,r0,#0x0a000000\n");
\r
430 // ot(" and r3,r10,r0,lsr #3 ;@ Undefined V behavior part II\n");
\r
431 // ot(" orr r10,r10,r3,lsl #4 ;@ V\n");
\r
432 ot(" movs r0,r0,lsl #4\n");
\r
433 ot(" orrmi r10,r10,#0x90000000 ;@ Undefined N+V behavior\n"); // this is what Musashi really does
\r
434 ot(" bicne r10,r10,#0x40000000 ;@ Z flag\n");
\r
438 ot(" ldr r0,[r7,#0x4c] ;@ Get X bit\n");
\r
439 ot(" mov r3,#0x00f00000\n");
\r
440 ot(" and r2,r3,r6,lsr #4\n");
\r
441 ot(" tst r0,#0x20000000\n");
\r
442 ot(" and r0,r3,r1,lsr #4\n");
\r
443 ot(" sub r0,r0,r2\n");
\r
444 ot(" subne r0,r0,#0x00100000\n");
\r
445 // ot(" tst r0,#0x00800000\n");
\r
446 // ot(" orreq r10,r10,#0x01000000 ;@ Undefined V behavior\n");
\r
447 ot(" cmp r0,#0x00900000\n");
\r
448 ot(" subhi r0,r0,#0x00600000 ;@ Decimal adjust units\n");
\r
450 ot(" mov r2,r1,lsr #28\n");
\r
451 ot(" add r0,r0,r2,lsl #24\n");
\r
452 ot(" mov r2,r6,lsr #28\n");
\r
453 ot(" sub r0,r0,r2,lsl #24\n");
\r
454 ot(" cmp r0,#0x09900000\n");
\r
455 ot(" orrhi r10,r10,#0xa0000000 ;@ N and C\n");
\r
456 ot(" addhi r0,r0,#0x0a000000\n");
\r
457 // ot(" and r3,r10,r0,lsr #3 ;@ Undefined V behavior part II\n");
\r
458 // ot(" orr r10,r10,r3,lsl #4 ;@ V\n");
\r
459 ot(" movs r0,r0,lsl #4\n");
\r
460 // ot(" orrmi r10,r10,#0x80000000 ;@ Undefined N behavior\n");
\r
461 ot(" bicne r10,r10,#0x40000000 ;@ Z flag\n");
\r
464 ot(" str r10,[r7,#0x4c] ;@ Save X bit\n");
\r
467 EaWrite(11, 0, dea,0,0x0e00,1);
\r
469 ot(" ldr r6,[r7,#0x54]\n");
\r
475 // 01001000 00eeeeee - nbcd <ea>
\r
483 if(EaCanWrite(ea)==0||EaAn(ea)) return 1;
\r
486 if(op!=use) { OpUse(op,use); return 0; } // Use existing handler
\r
488 OpStart(op,ea); Cycles=6;
\r
489 if(ea >= 8) Cycles+=2;
\r
491 EaCalcReadNoSE(6,0,ea,0,0x003f);
\r
493 // this is rewrite of Musashi's code
\r
494 ot(" ldr r2,[r7,#0x4c]\n");
\r
495 ot(" bic r10,r10,#0xb0000000 ;@ clear all flags, except Z\n");
\r
496 ot(" mov r0,r0,asl #24\n");
\r
497 ot(" and r2,r2,#0x20000000\n");
\r
498 ot(" add r2,r0,r2,lsr #5 ;@ add X\n");
\r
499 ot(" rsb r11,r2,#0x9a000000 ;@ do arithmetic\n");
\r
501 ot(" cmp r11,#0x9a000000\n");
\r
502 ot(" beq finish%.4x\n",op);
\r
505 ot(" mvn r3,r11,lsr #31 ;@ Undefined V behavior\n",op);
\r
506 ot(" and r2,r11,#0x0f000000\n");
\r
507 ot(" cmp r2,#0x0a000000\n");
\r
508 ot(" andeq r11,r11,#0xf0000000\n");
\r
509 ot(" addeq r11,r11,#0x10000000\n");
\r
510 ot(" and r3,r3,r11,lsr #31 ;@ Undefined V behavior part II\n",op);
\r
511 ot(" movs r1,r11,asr #24\n");
\r
512 ot(" bicne r10,r10,#0x40000000 ;@ Z\n");
\r
513 ot(" orr r10,r10,r3,lsl #28 ;@ save V\n",op);
\r
514 ot(" orr r10,r10,#0x20000000 ;@ C\n");
\r
517 EaWrite(6, 1, ea,0,0x3f,0,0);
\r
519 ot("finish%.4x%s\n",op,ms?"":":");
\r
520 ot(" tst r11,r11\n");
\r
521 ot(" orrmi r10,r10,#0x80000000 ;@ N\n");
\r
522 ot(" str r10,[r7,#0x4c] ;@ Save X\n");
\r
525 ot(" ldr r6,[r7,#0x54]\n");
\r
531 // --------------------- Opcodes 0x90c0+ ---------------------
\r
532 // Suba/Cmpa/Adda 1tt1nnnx 11eeeeee (tt=type, x=size, eeeeee=Source EA)
\r
533 int OpAritha(int op)
\r
536 int type=0,size=0,sea=0,dea=0;
\r
537 const char *asr="";
\r
539 // Suba/Cmpa/Adda/(invalid):
\r
540 type=(op>>13)&3; if (type>=3) return 1;
\r
542 size=(op>>8)&1; size++;
\r
543 dea=(op>>9)&7; dea|=8; // Dest=An
\r
544 sea=op&0x003f; // Source
\r
546 // See if we can do this opcode:
\r
547 if (EaCanRead(sea,size)==0) return 1;
\r
549 use=OpBase(op,size);
\r
550 use&=~0x0e00; // Use same opcode for An
\r
551 if (op!=use) { OpUse(op,use); return 0; } // Use existing handler
\r
553 OpStart(op,sea); Cycles=(size==2)?6:8;
\r
554 if(size==2&&(sea<0x10||sea==0x3c)) Cycles+=2;
\r
555 if(type==1) Cycles=6;
\r
557 // EA calculation order defines how situations like suba.w (A0)+, A0 get handled.
\r
558 // different emus act differently in this situation, I couldn't fugure which is right behaviour.
\r
561 EaCalcReadNoSE(-1,0,sea,size,0x003f);
\r
562 EaCalcReadNoSE(type!=1?11:-1,1,dea,2,0x0e00);
\r
567 EaCalcReadNoSE(type!=1?11:-1,1,dea,2,0x0e00);
\r
568 EaCalcReadNoSE(-1,0,sea,size,0x003f);
\r
572 if (size<2) ot(" mov r0,r0,asl #%d\n\n",size?16:24);
\r
573 if (size<2) asr=(char *)(size?",asr #16":",asr #24");
\r
575 if (type==0) ot(" sub r1,r1,r0%s\n",asr);
\r
576 if (type==1) ot(" cmp r1,r0%s ;@ Defines NZCV\n",asr);
\r
577 if (type==1) OpGetFlags(1,0); // Get Cmp flags
\r
578 if (type==2) ot(" add r1,r1,r0%s\n",asr);
\r
581 if (type!=1) EaWrite(11, 1, dea,2,0x0e00);
\r
588 // --------------------- Opcodes 0x9100+ ---------------------
\r
589 // Emit a Subx/Addx opcode, 1t01ddd1 zz00rsss addx.z Ds,Dd
\r
593 int type=0,size=0,dea=0,sea=0,mem=0;
\r
594 const char *asl="";
\r
598 size=(op>> 6)&3; if (size>=3) return 1;
\r
602 // See if we can do this opcode:
\r
603 if (EaCanRead(sea,size)==0) return 1;
\r
604 if (EaCanWrite(dea)==0) return 1;
\r
606 if (mem) { sea+=0x20; dea+=0x20; }
\r
608 use=op&~0x0e07; // Use same opcode for Dn
\r
609 if (size==0&&sea==0x27) use|=0x0007; // ___x.b -(a7)
\r
610 if (size==0&&dea==0x27) use|=0x0e00; // ___x.b -(a7)
\r
611 if (op!=use) { OpUse(op,use); return 0; } // Use existing handler
\r
613 OpStart(op,sea,dea); Cycles=4;
\r
614 if(size>=2) Cycles+=4;
\r
615 if(sea>=0x10) Cycles+=2;
\r
619 ot(";@ Get src/dest EA vals\n");
\r
620 EaCalc (0,0x000f, sea,size,1);
\r
621 EaRead (0, 6, sea,size,0x000f,1);
\r
622 EaCalcReadNoSE(11,0,dea,size,0x0e00);
\r
626 ot(";@ Get src/dest reg vals\n");
\r
627 EaCalcReadNoSE(-1,6,sea,size,0x0007);
\r
628 EaCalcReadNoSE(11,0,dea,size,0x0e00);
\r
629 if (size<2) ot(" mov r6,r6,asl #%d\n\n",size?16:24);
\r
632 if (size<2) asl=(char *)(size?",asl #16":",asl #24");
\r
634 ot(";@ Do arithmetic:\n");
\r
637 if (type==1 && size<2)
\r
639 ot(";@ Make sure the carry bit will tip the balance:\n");
\r
640 ot(" mvn r2,#0\n");
\r
641 ot(" orr r6,r6,r2,lsr #%i\n",(size==0)?8:16);
\r
645 if (type==0) ot(" rscs r1,r6,r0%s\n",asl);
\r
646 if (type==1) ot(" adcs r1,r6,r0%s\n",asl);
\r
647 ot(" orr r3,r10,#0xb0000000 ;@ for old Z\n");
\r
648 OpGetFlags(type==0,1,0); // subtract
\r
650 ot(" movs r2,r1,lsr #%i\n", size?16:24);
\r
651 ot(" orreq r10,r10,#0x40000000 ;@ add potentially missed Z\n");
\r
653 ot(" andeq r10,r10,r3 ;@ fix Z\n");
\r
656 ot(";@ Save result:\n");
\r
657 EaWrite(11, 1, dea,size,0x0e00,1);
\r
659 ot(" ldr r6,[r7,#0x54]\n");
\r
665 // --------------------- Opcodes 0xb000+ ---------------------
\r
666 // Emit a Cmp/Eor opcode, 1011rrrt xxeeeeee (rrr=Dn, t=cmp/eor, xx=size extension, eeeeee=ea)
\r
667 int OpCmpEor(int op)
\r
670 int size=0,ea=0,use=0;
\r
671 const char *asl="";
\r
673 // Get EA and register EA
\r
676 size=(op>>6)&3; if (size>=3) return 1;
\r
679 if (eor && (ea>>3) == 1) return 1; // not a valid mode for eor
\r
681 // See if we can do this opcode:
\r
682 if (EaCanRead(ea,size)==0) return 1;
\r
683 if (eor && EaCanWrite(ea)==0) return 1;
\r
684 if (EaAn(ea)&&(eor||size==0)) return 1;
\r
686 use=OpBase(op,size);
\r
687 use&=~0x0e00; // Use 1 handler for register d0-7
\r
688 if (op!=use) { OpUse(op,use); return 0; } // Use existing handler
\r
690 OpStart(op,ea); Cycles=4;
\r
692 if(ea>8) Cycles+=4;
\r
693 if(size>=2) Cycles+=4;
\r
695 if(size>=2) Cycles+=2;
\r
698 ot(";@ Get EA into r11 and value into r0:\n");
\r
699 EaCalcReadNoSE(eor?11:-1,0,ea,size,0x003f);
\r
701 ot(";@ Get register operand into r1:\n");
\r
702 EaCalcReadNoSE(-1,1,rea,size,0x0e00);
\r
704 if (size<2) ot(" mov r0,r0,asl #%d\n\n",size?16:24);
\r
705 if (size<2) asl=(char *)(size?",asl #16":",asl #24");
\r
707 ot(";@ Do arithmetic:\n");
\r
708 if (eor==0) ot(" rsbs r1,r0,r1%s\n",asl);
\r
711 ot(" eor r1,r0,r1%s\n",asl);
\r
712 ot(" adds r1,r1,#0 ;@ Defines NZ, clears CV\n");
\r
715 OpGetFlags(eor==0,0); // Cmp like subtract
\r
718 if (eor) EaWrite(11, 1,ea,size,0x003f,1);
\r
724 // Emit a Cmpm opcode, 1011ddd1 xx001sss (rrr=Adst, xx=size extension, sss=Asrc)
\r
727 int size=0,sea=0,dea=0,use=0;
\r
728 const char *asl="";
\r
730 // get size, get EAs
\r
731 size=(op>>6)&3; if (size>=3) return 1;
\r
735 use=op&~0x0e07; // Use 1 handler for all registers..
\r
736 if (size==0&&sea==0x1f) use|=0x0007; // ..except (a7)+
\r
737 if (size==0&&dea==0x1f) use|=0x0e00;
\r
738 if (op!=use) { OpUse(op,use); return 0; } // Use existing handler
\r
740 OpStart(op,sea); Cycles=4;
\r
742 ot(";@ Get src operand into r11:\n");
\r
743 EaCalc (0,0x0007, sea,size,1);
\r
744 EaRead (0, 11, sea,size,0x0007,1);
\r
746 ot(";@ Get dst operand into r0:\n");
\r
747 EaCalcReadNoSE(-1,0,dea,size,0x0e00);
\r
749 if (size<2) asl=(char *)(size?",asl #16":",asl #24");
\r
751 ot(" rsbs r0,r11,r0%s\n",asl);
\r
752 OpGetFlags(1,0); // Cmp like subtract
\r
760 // Emit a Chk opcode, 0100ddd1 x0eeeeee (rrr=Dn, x=size extension, eeeeee=ea)
\r
764 int size=0,ea=0,use=0;
\r
766 // Get EA and register EA
\r
769 size=1; // word operation
\r
770 else size=2; // long
\r
773 if (EaAn(ea)) return 1; // not a valid mode
\r
774 if (size!=1) return 1; // 000 variant only supports word
\r
776 // See if we can do this opcode:
\r
777 if (EaCanRead(ea,size)==0) return 1;
\r
779 use=OpBase(op,size);
\r
780 use&=~0x0e00; // Use 1 handler for register d0-7
\r
781 if (op!=use) { OpUse(op,use); return 0; } // Use existing handler
\r
783 OpStart(op,ea); Cycles=10;
\r
785 ot(";@ Get value into r0:\n");
\r
786 EaCalcReadNoSE(-1,0,ea,size,0x003f);
\r
788 ot(";@ Get register operand into r1:\n");
\r
789 EaCalcReadNoSE(-1,1,rea,size,0x0e00);
\r
791 if (size<2) ot(" mov r0,r0,asl #%d\n",size?16:24);
\r
792 if (size<2) ot(" mov r1,r1,asl #%d\n\n",size?16:24);
\r
794 ot(";@ get flags, including undocumented ones\n");
\r
795 ot(" and r3,r10,#0x80000000\n");
\r
796 ot(" adds r1,r1,#0 ;@ Defines NZ, clears CV\n");
\r
799 ot(";@ is reg negative?\n");
\r
800 ot(" bmi chktrap%.4x\n",op);
\r
802 ot(";@ Do arithmetic:\n");
\r
803 ot(" bic r10,r10,#0x80000000 ;@ N\n");
\r
804 ot(" cmp r1,r0\n");
\r
805 ot(" bgt chktrap%.4x\n",op);
\r
807 ot(";@ old N remains\n");
\r
808 ot(" orr r10,r10,r3\n");
\r
811 ot("chktrap%.4x%s ;@ CHK exception:\n",op,ms?"":":");
\r
812 ot(" mov r0,#6\n");
\r
813 ot(" bl Exception\n");
\r