ARM DSP: fore some reason I neglected dsp_downsample completely. Do a small reordering.
[kugel-rb.git] / apps / plugins / rockboy / dynarec.c
blob3c71115654965656dad00f7c889c2bff6042e094
1 #include "rockmacros.h"
2 #include "defs.h"
3 #include "regs.h"
4 #include "hw.h"
5 #include "cpu-gb.h"
6 #include "lcdc.h"
7 #include "mem.h"
8 #include "fastmem.h"
9 #include "cpuregs.h"
10 #include "cpucore.h"
12 void *dynapointer,*branchp[10];
13 int blockclen;
15 #define DYNA_DEBUG 1
17 #define DWRITEB(a) *((unsigned char *) dynapointer)=(a); dynapointer+=1
18 #define DWRITEW(a) *((unsigned short *) dynapointer)=(a); dynapointer+=2
19 #define DWRITEL(a) *((unsigned long *) dynapointer)=(a); dynapointer+=4
20 #define FETCH (readb(PC++))
23 * dest=0xFF00;
24 * dest&=src;
25 * dest=dest>>8;
28 #define GETUPPER(src,dest) \
29 DYNA_MOVE_l_i_to_r(0xFF00,(dest)); \
30 DYNA_AND_l_r_to_r((src),(dest)); \
31 DYNA_ASHIFT_l(0,(dest),0,0)
34 * dest&=0xFF;
35 * src&=0xFF;
36 * src=src<<8;
37 * dest|=src;
39 #define PUTUPPER(src,dest) \
40 DYNA_AND_l_i_to_r(0xFF,(dest)); \
41 DYNA_AND_l_i_to_r(0xFF,(src)); \
42 DYNA_ASHIFT_l(0,(src),1,0); \
43 DYNA_OR_l_r_to_r((src),(dest))
45 * movea.l &cpu.a, %a3
46 * movem.l d1-d7/a0-a1 , (%a3)
47 * jsr (n)
48 * movea.l &cpu.a, %a3
49 * movem.l (%a3), d1-d7/a0-a1
51 #define CALL_NATIVE(n) \
52 DYNA_MOVEA_l_i_to_r(&cpu.a,3); \
53 DYNA_MOVEM(3,0x3FE,0); \
54 DYNA_JSR((n)); \
55 DYNA_MOVEA_l_i_to_r(&cpu.a,3); \
56 DYNA_MOVEM(3,0x3FE,1);
59 * SUBQ 2, %a0 decrease gb sp
60 * PEA #(n) push n
61 * PUSH %a0 push gb sp
62 * call_native writew(SP, (n))
63 * ADDQ 8, %a7
65 #define PUSH(n) \
66 DYNA_SUBQ_l_i_to_r(2,0,1); \
67 DYNA_PEA_w_i((n)); \
68 DYNA_PUSH_l_r(0,1); \
69 CALL_NATIVE(&writew); \
70 DYNA_ADDQ_l_i_to_r(0,7,1);
73 * PUSH %a0 push gb sp
74 * call_native readw(SP);
75 * addq 4, a7
76 * addq 2, a0
77 * movea.w %d0, (n)
80 #define POPA(n) \
81 DYNA_PUSH_l_r(0,1); \
82 CALL_NATIVE(&readw); \
83 DYNA_ADDQ_l_i_to_r(4,7,1); \
84 DYNA_ADDQ_l_i_to_r(2,0,1); \
85 DYNA_MOVEA_w_r_to_r(0,(n),0);
87 #define ADD(n) \
88 DYNA_MOVEQ_l_i_to_r(0x0,7); \
89 DYNA_MOVE_l_r_to_r(1,0,0); \
90 DYNA_ADD_l_r_to_r((n),1); \
91 DYNA_XOR_l_r_to_r(1,0); \
92 DYNA_XOR_l_r_to_r((n),0); \
93 DYNA_LSHIFT_l(1,0,1,0); \
94 DYNA_AND_l_i_to_r(0x20,0); \
95 DYNA_OR_l_r_to_r(0,7); \
96 DYNA_TST_b_r(1,0); \
97 DYNA_SET_b_r(0,0x7); \
98 DYNA_AND_l_i_to_r(0x80,0); \
99 DYNA_OR_l_r_to_r(0,7); \
100 DYNA_MOVE_l_r_to_r(1,0,0); \
101 DYNA_LSHIFT_l(4,0,0,0); \
102 DYNA_ANDI_l_i_to_r(0x10,0); \
103 DYNA_OR_l_r_to_r(0,7); \
104 DYNA_AND_l_i_to_r(0xFF,1);
106 #define SUBTRACT(n) \
107 DYNA_MOVEQ_l_i_to_r(0x40,7); \
108 DYNA_MOVE_l_r_to_r(1,0,0); \
109 DYNA_SUB_l_r_to_r((n),1,0); \
110 DYNA_XOR_l_r_to_r(1,0); \
111 DYNA_XOR_l_r_to_r((n),0); \
112 DYNA_LSHIFT_l(1,0,1,0); \
113 DYNA_AND_l_i_to_r(0x20,0); \
114 DYNA_OR_l_r_to_r(0,7); \
115 DYNA_TST_b_r(1,0); \
116 DYNA_SET_b_r(0,0x7); \
117 DYNA_AND_l_i_to_r(0x80,0); \
118 DYNA_OR_l_r_to_r(0,7); \
119 DYNA_MOVE_l_r_to_r(1,0,0); \
120 DYNA_LSHIFT_l(4,0,0,0); \
121 DYNA_AND_l_i_to_r(0x10,0); \
122 DYNA_OR_l_r_to_r(0,7);
124 #define CMP(n) \
125 DYNA_MOVEA_l_r_to_r(1,3,0); \
126 SUBTRACT((n)); \
127 DYNA_MOVE_l_r_to_r(3,1,1);
129 #define SUB(n) \
130 SUBTRACT((n)); \
131 DYNA_ANDI_l_i_to_r(0xFF,1);
134 void DYNA_MOVE_b_r_to_r(un8 src,un8 dest)
136 DWRITEW(0x1000|(src&0x7)|(dest&0x7)<<9);
139 void DYNA_ASHIFT_l(un8 src, un8 dest, int left, int src_is_reg)
141 unsigned short opcode;
142 opcode=(0xE080)|((src&0x7)<<9)|(dest&0x7);
143 if(left)
144 opcode|=0x100;
145 if(src_is_reg)
146 opcode|=0x20;
147 DWRITEW(opcode);
150 void DYNA_LSHIFT_l(un8 src, un8 dest, int left, int src_is_reg)
152 unsigned short opcode=0xE088|((src&0x7)<<9)|(dest&0x7);
153 if(left)
154 opcode|=0x100;
155 if(src_is_reg)
156 opcode|=0x20;
157 DWRITEW(opcode);
160 void DYNA_MOVE_l_i_to_r(un32 imm, un8 dest)
162 DWRITEW(0x203C|(dest&0x7)<<9);
163 DWRITEL(imm); /* endianness? */
166 void DYNA_MOVE_l_i_to_m(un32 imm, un8 dest_a)
168 DWRITEW(0x20FC|((dest_a&0x7)<<9));
169 DWRITEL(imm);
172 void DYNA_MOVE_l_r_to_m(un8 src,un8 dest_a)
174 DWRITEW(0x2080|(dest_a&0x7)<<9|(src&0x7));
177 void DYNA_MOVE_l_r_to_r(un8 src, un8 dest, int src_is_areg)
179 unsigned short opcode=0x2000|((dest&0x7)<<9)|(src&0x7);
180 if(src_is_areg)
181 opcode|=0x8;
182 DWRITEW(opcode);
185 void DYNA_MOVE_w_r_to_r(un8 src, un8 dest, int src_is_areg)
187 unsigned short opcode=0x3000|((dest&0x7)<<9)|(src&0x7);
188 if(src_is_areg)
189 opcode|=0x8;
190 DWRITEW(opcode);
193 void DYNA_MOVEQ_l_i_to_r(un8 imm, un8 dest)
195 DWRITEW(0x7000|((dest&0x7)<<9)|imm);
198 void DYNA_PEA_w_i(un16 imm)
200 DWRITEW(0x4878);
201 DWRITEW(imm);
204 void DYNA_PUSH_l_r(un8 reg,int src_is_areg)
206 unsigned short value= 0x2F00|(reg&0x7);
207 if(src_is_areg)
208 value|=0x8;
209 DWRITEW(value);
212 void DYNA_MOVEA_l_i_to_r(un32 imm, un8 dest)
214 DWRITEW(0x207C|(dest&0x7)<<9);
215 DWRITEL(imm);
218 void DYNA_MOVEA_w_r_to_r(un8 src, un8 dest, int src_is_areg)
220 unsigned short value=0x3040|((dest&0x7)<<9)|(src&0x7);
221 if(src_is_areg)
222 value|=0x8;
223 DWRITEW(value);
226 void DYNA_MOVEA_l_r_to_r(un8 src, un8 dest, int src_is_areg)
228 unsigned short value=0x2040|((dest&0x7)<<9)|(src&0x7);
229 if(src_is_areg)
230 value|=0x8;
231 DWRITEW(value);
235 void DYNA_RET(void)
237 DWRITEW(0x4E75);
240 void DYNA_AND_l_i_to_r(un32 imm, un8 dest)
242 DWRITEW(0x0280|(dest&0x7));
243 DWRITEL(imm);
246 void DYNA_AND_l_r_to_r(un8 src,un8 dest)
248 DWRITEW(0xC080|((dest&0x7)<<9)|(src&0x7));
251 void DYNA_OR_l_r_to_r(un8 src,un8 dest)
253 DWRITEW(0x8080|((dest&0x7)<<9)|(src&0x7));
256 void DYNA_OR_l_i_to_r(un32 imm,un8 dest)
258 DWRITEW(0x0080|(dest&0x7));
259 DWRITEL(imm);
262 void DYNA_CLR_l_m(un32 addr)
264 DWRITEW(0x42B9);
265 DWRITEL(addr);
268 void DYNA_CLR_l_r(un8 reg)
270 DWRITEW(0x4280|(reg&0x7));
273 void DYNA_CLR_w_r(un8 reg)
275 DWRITEW(0x42C0|(reg&0x7));
279 void DYNA_CLR_b_r(un8 reg)
281 DWRITEW(0x4200|(reg&0x7));
285 void DYNA_ADDQ_l_i_to_r(un8 imm, un8 reg, int dest_is_a)
287 unsigned short value=0x5080|(imm&0x7)<<9|(reg&0x7);
288 if(dest_is_a)
289 value|=0x8;
290 DWRITEW(value);
293 void DYNA_ADD_l_r_to_r(un8 src, un8 dest, int src_is_areg)
295 unsigned short value=0xD080|((dest&0x7)<<9)|(src&0x7);
296 if(src_is_areg)
297 value|=0x8;
298 DWRITEW(value);
301 void DYNA_JSR(void *addr)
303 DWRITEW(0x4EB9);
304 DWRITEL(addr);
307 void DYNA_MOVEM(un8 areg,un16 mask, int frommem)
309 unsigned short value=0x48D0|(areg&0x7);
310 if(frommem)
311 value|=0x400;
312 DWRITEW(value);
313 DWRITEW(mask);
316 void DYNA_SUBQ_l_i_to_r(un8 imm, un8 reg, int addr_reg)
318 unsigned short value=0x5180|(reg&0x7)|((imm&0x7)<<9);
319 if(addr_reg)
320 value|=0x8;
321 DWRITEW(value);
324 void DYNA_SUB_l_r_to_r(un8 src, un8 dest, int is_areg)
326 unsigned short value=0x9080|((dest&0x7)<<9)|(src&0x7);
327 if(is_areg)
328 value|=0x8;
329 DWRITEW(value);
332 void DYNA_EXT_l(un8 reg)
334 DWRITEW(0x48C0|(reg&0x7));
337 void DYNA_BCC_c(un8 cond, int size,int i)
339 un32 displace=dynapointer-branchp[i];
340 if(!branchp[i])
342 die("Dynarec error! BCC trying to write branch without dummy");
343 return;
345 if((size==2&&displace>0x7f) || (size==4 && displace>0x7FFF))
346 die("Dynarec error! BCC invalid displacement");
347 else if(displace>0&&displace<0x7F)
348 *( (unsigned short *) branchp[i])=0x6000|((cond&0xF)<<8)|(displace&0xFF);
349 else if(displace>0x7F&&displace<0x7FFF)
351 *( (unsigned short *) branchp[i])=0x6000|((cond&0xF)<<8);
352 branchp[i]+=2;
353 *( (unsigned short *) branchp[i])=displace;
355 else
356 die("Dynarec error! BCC invalid displacement");
358 branchp[i]=0;
361 void DYNA_DUMMYBRANCH(int size,int i)
363 branchp[i]=dynapointer;
364 dynapointer+=size;
367 void DYNA_TST_l_r(un8 reg,int is_areg)
369 unsigned short opcode=0x4A80|(reg&0x7);
370 if(is_areg)
371 opcode|=0x8;
372 DWRITEW(opcode);
375 void DYNA_TST_b_r(un8 reg,int is_areg)
377 unsigned short opcode=0x4A00|(reg&0x7);
378 if(is_areg)
379 opcode|=0x8;
380 DWRITEW(opcode);
384 void DYNA_BTST_l_r(un8 bit, un8 reg)
386 DWRITEW(0x0800|(reg&0x7));
387 DWRITEW(bit);
390 void DYNA_NEG_l(un8 reg)
392 DWRITEW(0x4480|(reg&0x7));
395 void DYNA_XOR_l_r_to_r(un8 src, un8 dest)
397 DWRITEW(0xB180|((dest&0x7)<<9)|(src&0x7));
400 void DYNA_SET_b_r(un8 src, un8 cond)
402 DWRITEW(0x50C0|((cond)&0xF)<<8|(src&0x7));
405 void DYNA_INC_l_r(un8 dest,int is_areg)
407 DYNA_ADDQ_l_i_to_r(1,dest,is_areg);
410 void DYNA_DEC_l_r(un8 dest,int is_areg)
412 DYNA_SUBQ_l_i_to_r(1,dest,is_areg);
416 void dynamic_recompile (struct dynarec_block *newblock)
418 int done=0,writepc=1,fd;
419 byte op;
420 unsigned int oldpc=PC;
421 unsigned short temp;
422 unsigned int tclen=0,clen;
423 char meow[500];
424 dynapointer=malloc(512);
425 newblock->block=dynapointer;
426 #ifdef DYNA_DEBUG
427 snprintf(meow,499,"/dyna_0x%x_asm.rb",PC);
428 fd=open(meow,O_WRONLY|O_CREAT|O_TRUNC, 0666);
429 if(fd<0)
431 die("couldn't open dyna debug file");
432 return;
434 #endif
435 snprintf(meow,499,"Recompiling 0x%x",oldpc);
436 rb->splash(HZ*1,meow);
437 while(!done)
439 #ifdef DYNA_DEBUG
440 fdprintf(fd,"0x%x: ",PC);
441 #endif
442 op=FETCH;
443 clen = cycles_table[op];
444 tclen+=clen;
445 switch(op) {
446 case 0x00: /* NOP */
447 break;
448 case 0x01: /* LD BC,imm */
449 /* warning (do we have endianness right?) */
450 #ifdef DYNA_DEBUG
451 fdprintf(fd,"LD BC,#0x%x\n",readw(xPC));
452 #endif
453 temp=readw(xPC);
454 DYNA_MOVEQ_l_i_to_r((temp&0xFF00)>>8,2);
455 DYNA_MOVEQ_l_i_to_r(temp&0xFF,3);
456 PC+=2;
457 break;
458 case 0x02: /* LD (BC),A */
459 #ifdef DYNA_DEBUG
460 fdprintf(fd, "LD (BC),A\n");
461 #endif
462 break; /* FIXME: Implement */
463 case 0x03: /* INC BC */
464 #ifdef DYNA_DEBUG
465 fdprintf(fd, "INC BC\n");
466 #endif
467 break; /* FIXME: Implement */
468 case 0x04: /* INC B */
469 #ifdef DYNA_DEBUG
470 fdprintf(fd, "INC B\n");
471 #endif
472 DYNA_INC_l_r(2,0); /* Is this right? */
473 break;
474 case 0x05: /* DEC B */
475 #ifdef DYNA_DEBUG
476 fdprintf(fd, "DEC B\n");
477 #endif
478 DYNA_DEC_l_r(2,0); /* Is this right? */
479 break;
480 case 0x06: /* LD B,imm */
481 #ifdef DYNA_DEBUG
482 fdprintf(fd,"LD B,#0x%x\n",readb(xPC));
483 #endif
484 DYNA_MOVEQ_l_i_to_r(FETCH,2);
485 break;
486 case 0x07: /* RLCA */
487 #ifdef DYNA_DEBUG
488 fdprintf(fd, "RLCA\n");
489 #endif
490 break; /* FIXME: Implement */
491 case 0x08: /* LD imm,SP */
492 #ifdef DYNA_DEBUG
493 fdprintf(fd, "LD imm,SP\n");
494 #endif
495 break; /* FIXME: Implement */
496 case 0x09: /* ADD HL,BC */
497 #ifdef DYNA_DEBUG
498 fdprintf(fd, "ADD HL,BC\n");
499 #endif
500 break; /* FIXME: Implement */
501 case 0x0A: /* LD A,(BC) */
502 #ifdef DYNA_DEBUG
503 fdprintf(fd, "LD A,(BC)\n");
504 #endif
505 break; /* FIXME: Implement */
506 case 0x0B: /* DEC BC */
507 #ifdef DYNA_DEBUG
508 fdprintf(fd,"DEC BC\n");
509 #endif
510 DYNA_TST_b_r(3,0); /* test C */
511 DYNA_DUMMYBRANCH(2,0);
512 DYNA_DEC_l_r(2,0); /* dec B */
513 DYNA_BCC_c(0x6,2,0); /* jump here if not zero */
514 DYNA_DEC_l_r(3,0); /* dec C */
515 break;
516 case 0x0C: /* INC C */
517 #ifdef DYNA_DEBUG
518 fdprintf(fd, "INC C\n");
519 #endif
520 DYNA_INC_l_r(3,0); /* Is this right? */
521 break;
522 case 0x0D: /* DEC C */
523 #ifdef DYNA_DEBUG
524 fdprintf(fd, "DEC C\n");
525 #endif
526 DYNA_DEC_l_r(3,0); /* Is this right? */
527 break;
528 case 0x0E: /* LD C,imm */
529 #ifdef DYNA_DEBUG
530 fdprintf(fd,"LD C,#0x%x\n",readb(xPC));
531 #endif
532 DYNA_MOVEQ_l_i_to_r(FETCH,3);
533 break;
534 case 0x0F: /* RRCA */
535 #ifdef DYNA_DEBUG
536 fdprintf(fd, "RRCA\n");
537 #endif
538 break; /* FIXME: Implement */
539 case 0x10: /* STOP */
540 #ifdef DYNA_DEBUG
541 fdprintf(fd, "STOP\n");
542 #endif
543 break; /* FIXME: Implement */
544 case 0x11: /* LD DE,imm */
545 #ifdef DYNA_DEBUG
546 fdprintf(fd,"LD DE,#0x%x\n",readw(xPC));
547 #endif
548 temp=readw(xPC);
549 DYNA_MOVEQ_l_i_to_r((temp&0xFF00)>>8,4);
550 DYNA_MOVEQ_l_i_to_r(temp&0xFF,5);
551 PC += 2;
552 break;
553 case 0x12: /* LD (DE),A */
554 #ifdef DYNA_DEBUG
555 fdprintf(fd, "LD (DE),A\n");
556 #endif
557 break; /* FIXME: Implement */
558 case 0x13: /* INC DE */
559 #ifdef DYNA_DEBUG
560 fdprintf(fd, "INC DE\n");
561 #endif
562 break; /* FIXME: Implement */
563 case 0x14: /* INC D */
564 #ifdef DYNA_DEBUG
565 fdprintf(fd, "INC D\n");
566 #endif
567 DYNA_INC_l_r(4,0); /* Is this right? */
568 break;
569 case 0x15: /* DEC D */
570 #ifdef DYNA_DEBUG
571 fdprintf(fd, "DEC D\n");
572 #endif
573 DYNA_DEC_l_r(4,0); /* Is this right? */
574 break;
575 case 0x16: /* LD D,imm */
576 #ifdef DYNA_DEBUG
577 fdprintf(fd,"LD D,#0x%x\n",readb(xPC));
578 #endif
579 DYNA_MOVEQ_l_i_to_r(FETCH,4);
580 break;
581 case 0x17: /* RLA */
582 #ifdef DYNA_DEBUG
583 fdprintf(fd, "RLA\n");
584 #endif
585 break; /* FIXME: Implement */
586 case 0x18: /* JR */
587 #ifdef DYNA_DEBUG
588 fdprintf(fd, "JR\n");
589 #endif
590 break; /* FIXME: Implement */
591 case 0x19: /* ADD HL,DE */
592 #ifdef DYNA_DEBUG
593 fdprintf(fd, "ADD HL,DE\n");
594 #endif
595 break; /* FIXME: Implement */
596 case 0x1A: /* LD A,(DE) */
597 #ifdef DYNA_DEBUG
598 fdprintf(fd, "LD A,(DE)\n");
599 #endif
600 break; /* FIXME: Implement */
601 case 0x1B: /* DEC DE */
602 #ifdef DYNA_DEBUG
603 fdprintf(fd,"DEC DE\n");
604 #endif
605 DYNA_TST_b_r(5,0); /* test E */
606 DYNA_DUMMYBRANCH(4,0);
607 DYNA_DEC_l_r(4,0); /* dec D */
608 DYNA_BCC_c(0x6,4,0); /* jump here if not zero */
609 DYNA_DEC_l_r(5,0); /* dec E */
610 break;
611 case 0x1C: /* INC E */
612 #ifdef DYNA_DEBUG
613 fdprintf(fd, "INC E\n");
614 #endif
615 DYNA_INC_l_r(5,0); /* Is this right? */
616 break;
617 case 0x1D: /* DEC E */
618 #ifdef DYNA_DEBUG
619 fdprintf(fd, "DEC E\n");
620 #endif
621 DYNA_DEC_l_r(5,0); /* Is this right? */
622 break;
623 case 0x1E: /* LD E,imm */
624 #ifdef DYNA_DEBUG
625 fdprintf(fd,"LD E,#0x%x\n",readb(xPC));
626 #endif
627 DYNA_MOVEQ_l_i_to_r(FETCH,5);
628 break;
629 case 0x1F: /* RRA */
630 #ifdef DYNA_DEBUG
631 fdprintf(fd, "RRA\n");
632 #endif
633 break; /* FIXME: Implement */
634 case 0x20: /* JR NZ */
635 #ifdef DYNA_DEBUG
636 fdprintf(fd,"JR NZ\n");
637 #endif
638 DYNA_BTST_l_r(8,7); /* btst #8,d7 */
639 DYNA_DUMMYBRANCH(2,0);
640 DYNA_MOVEA_l_i_to_r(&blockclen,3);
641 DYNA_MOVE_l_i_to_m(tclen,3);
642 DYNA_MOVEA_l_i_to_r(PC+1+(signed char)readb(PC),1);
643 DYNA_RET();
644 DYNA_BCC_c(0x6,2,0); /* jump here if bit is not zero */
645 tclen--;
646 PC++;
647 break;
648 case 0x21: /* LD HL,imm */
649 #ifdef DYNA_DEBUG
650 fdprintf(fd,"LD HL,#0x%x\n",readw(xPC));
651 #endif
652 DYNA_MOVE_l_i_to_r(readw(xPC),6);
653 PC += 2;
654 break;
655 case 0x22: /* LDI (HL), A */
656 #ifdef DYNA_DEBUG
657 fdprintf(fd,"LDI (HL),A\n");
658 #endif
659 /* DYNA_PUSH_l_r(1,0);
660 DYNA_PUSH_l_r(6,0);
661 CALL_NATIVE(&writeb);
662 DYNA_ADDQ_l_i_to_r(0,7,1);
663 DYNA_INC_l_r(6,0);*/
664 break;
665 case 0x23: /* INC HL */
666 #ifdef DYNA_DEBUG
667 fdprintf(fd, "INC HL\n");
668 #endif
669 break; /* FIXME: Implement */
670 case 0x24: /* INC H */
671 #ifdef DYNA_DEBUG
672 fdprintf(fd, "INC H\n");
673 #endif
674 break; /* FIXME: Implement */
675 case 0x25: /* DEC H */
676 #ifdef DYNA_DEBUG
677 fdprintf(fd, "DEC H\n");
678 #endif
679 break; /* FIXME: Implement */
680 case 0x26: /* LD H,imm */
681 #ifdef DYNA_DEBUG
682 fdprintf(fd,"LD H,#0x%x\n",readb(xPC));
683 #endif
684 DYNA_AND_l_i_to_r(0xFF,6);
685 DYNA_OR_l_i_to_r(FETCH<<8,6);
686 break;
687 case 0x27: /* DAA */
688 #ifdef DYNA_DEBUG
689 fdprintf(fd, "DAA\n");
690 #endif
691 break; /* FIXME: Implement */
692 case 0x28: /* JR Z */
693 #ifdef DYNA_DEBUG
694 fdprintf(fd, "JR Z\n");
695 #endif
696 break; /* FIXME: Implement */
697 case 0x29: /* ADD HL, HL */
698 #ifdef DYNA_DEBUG
699 fdprintf(fd, "ADD HL,HL\n");
700 #endif
701 break; /* FIXME: Implement */
702 case 0x2A: /* LD A,(HLI) */
703 #ifdef DYNA_DEBUG
704 fdprintf(fd, "LD A,(HLI)\n");
705 #endif
706 break; /* FIXME: Implement */
707 case 0x2B: /* DEC HL */
708 #ifdef DYNA_DEBUG
709 fdprintf(fd, "DEC HL\n");
710 #endif
711 break; /* FIXME: Implement */
712 case 0x2C: /* INC L */
713 #ifdef DYNA_DEBUG
714 fdprintf(fd, "INC L\n");
715 #endif
716 break; /* FIXME: Implement */
717 case 0x2D: /* DEC L */
718 #ifdef DYNA_DEBUG
719 fdprintf(fd, "DEC L\n");
720 #endif
721 break; /* FIXME: Implement */
722 case 0x2E: /* LD L,imm */
723 #ifdef DYNA_DEBUG
724 fdprintf(fd,"LD L,#0x%x\n",readb(xPC));
725 #endif
726 DYNA_AND_l_i_to_r(0xFF00,6);
727 DYNA_OR_l_i_to_r(FETCH,6);
728 break;
729 case 0x2F: /* CPL */
730 #ifdef DYNA_DEBUG
731 fdprintf(fd, "CPL\n");
732 #endif
733 break; /* FIXME: Implement */
734 case 0x30: /* JR NC */
735 #ifdef DYNA_DEBUG
736 fdprintf(fd, "JR NC\n");
737 #endif
738 break; /* FIXME: Implement */
739 case 0x31: /* LD SP,imm */
740 #ifdef DYNA_DEBUG
741 fdprintf(fd,"LD SP,#0x%x\n",readw(xPC));
742 #endif
743 DYNA_MOVEA_l_i_to_r(readw(xPC),0);
744 PC += 2;
745 break;
746 case 0x32: /* LD (HLD),A */
747 #ifdef DYNA_DEBUG
748 fdprintf(fd, "LD (HLD),A\n");
749 #endif
750 break; /* FIXME: Implement */
751 case 0x33: /* INC SP */
752 #ifdef DYNA_DEBUG
753 fdprintf(fd, "INC SP\n");
754 #endif
755 break; /* FIXME: Implement */
756 case 0x34: /* INC (HL) */
757 #ifdef DYNA_DEBUG
758 fdprintf(fd, "INC (HL)\n");
759 #endif
760 break; /* FIXME: Implement */
761 case 0x35: /* DEC (HL) */
762 #ifdef DYNA_DEBUG
763 fdprintf(fd, "DEC (HL)\n");
764 #endif
765 break; /* FIXME: Implement */
766 case 0x36: /* LD (HD),imm */
767 #ifdef DYNA_DEBUG
768 fdprintf(fd, "LD (HD),imm\n");
769 #endif
770 break; /* FIXME: Implement */
771 case 0x37: /* SCF */
772 #ifdef DYNA_DEBUG
773 fdprintf(fd, "SCF\n");
774 #endif
775 break; /* FIXME: Implement */
776 case 0x38: /* JR C */
777 #ifdef DYNA_DEBUG
778 fdprintf(fd, "JR C\n");
779 #endif
780 break; /* FIXME: Implement */
781 case 0x39: /* ADD HL,SP */
782 #ifdef DYNA_DEBUG
783 fdprintf(fd, "ADD HL,SP\n");
784 #endif
785 break; /* FIXME: Implement */
786 case 0x3A: /* LD A,(HLD) */
787 #ifdef DYNA_DEBUG
788 fdprintf(fd, "LD A,(HLD)\n");
789 #endif
790 break; /* FIXME: Implement */
791 case 0x3B: /* DEC SP */
792 #ifdef DYNA_DEBUG
793 fdprintf(fd, "DEC SP\n");
794 #endif
795 break; /* FIXME: Implement */
796 case 0x3C: /* INC A */
797 #ifdef DYNA_DEBUG
798 fdprintf(fd, "INC A");
799 #endif
800 DYNA_INC_l_r(1,0); /* Is this right? */
801 break;
802 case 0x3D: /* DEC A */
803 #ifdef DYNA_DEBUG
804 fdprintf(fd, "DEC A");
805 #endif
806 DYNA_DEC_l_r(1,0); /* Is this right? */
807 break;
808 case 0x3E: /* LD A,imm */
809 #ifdef DYNA_DEBUG
810 fdprintf(fd,"LD A,#0x%x\n",readb(xPC));
811 #endif
812 DYNA_MOVEQ_l_i_to_r(FETCH,1);
813 break;
814 case 0x3F: /* CCF */
815 #ifdef DYNA_DEBUG
816 fdprintf(fd, "CCF\n");
817 #endif
818 break; /* FIXME: Implement */
819 case 0x40: /* LD B,B */
820 #ifdef DYNA_DEBUG
821 fdprintf(fd, "LD B,B\n");
822 #endif
823 break;
824 case 0x41: /* LD B,C */
825 #ifdef DYNA_DEBUG
826 fdprintf(fd,"LD B,C\n");
827 #endif
828 DYNA_MOVE_b_r_to_r(3,2);
829 break;
830 case 0x42: /* LD B,D */
831 #ifdef DYNA_DEBUG
832 fdprintf(fd,"LD B,D\n");
833 #endif
834 DYNA_MOVE_b_r_to_r(4,2);
835 break;
836 case 0x43: /* LD B,E */
837 #ifdef DYNA_DEBUG
838 fdprintf(fd,"LD B,E\n");
839 #endif
840 DYNA_MOVE_b_r_to_r(5,2);
841 break;
842 case 0x44: /* LD B,H */
843 #ifdef DYNA_DEBUG
844 fdprintf(fd,"LD B,H\n");
845 #endif
846 GETUPPER(6,0);
847 DYNA_MOVE_b_r_to_r(0,2);
848 break;
849 case 0x45: /* LD B,L */
850 #ifdef DYNA_DEBUG
851 fdprintf(fd,"LD B,L\n");
852 #endif
853 DYNA_MOVE_b_r_to_r(6,2);
854 break;
855 case 0x46: /* LD B,(HL) */
856 #ifdef DYNA_DEBUG
857 fdprintf(fd, "LD B,(HL)\n");
858 #endif
859 break; /* FIXME: Implement */
860 case 0x47: /* LD B,A */
861 #ifdef DYNA_DEBUG
862 fdprintf(fd,"LD B,A\n");
863 #endif
864 DYNA_MOVE_b_r_to_r(1,2);
865 break;
866 case 0x48: /* LD C,B */
867 #ifdef DYNA_DEBUG
868 fdprintf(fd,"LD C,B\n");
869 #endif
870 DYNA_MOVE_b_r_to_r(2,3);
871 break;
872 case 0x49: /* LD C,C */
873 break;
874 case 0x4A: /* LD C,D */
875 #ifdef DYNA_DEBUG
876 fdprintf(fd,"LD C,D\n");
877 #endif
878 DYNA_MOVE_b_r_to_r(4,3);
879 break;
880 case 0x4B: /* LD C,E */
881 #ifdef DYNA_DEBUG
882 fdprintf(fd,"LD C,E\n");
883 #endif
884 DYNA_MOVE_b_r_to_r(5,3);
885 break;
886 case 0x4C: /* LD C,H */
887 #ifdef DYNA_DEBUG
888 fdprintf(fd,"LD C,H\n");
889 #endif
890 GETUPPER(6,0);
891 DYNA_MOVE_b_r_to_r(0,3);
892 break;
893 case 0x4D: /* LD C,L */
894 #ifdef DYNA_DEBUG
895 fdprintf(fd,"LD C,L\n");
896 #endif
897 DYNA_MOVE_b_r_to_r(6,3);
898 break;
899 case 0x4E: /* LD C,(HL) */
900 #ifdef DYNA_DEBUG
901 fdprintf(fd, "LD C,(HL)\n");
902 #endif
903 break; /* FIXME: Implement */
904 case 0x4F: /* LD C,A */
905 #ifdef DYNA_DEBUG
906 fdprintf(fd,"LD C,A\n");
907 #endif
908 DYNA_MOVE_b_r_to_r(1,3);
909 break;
910 case 0x50: /* LD D,B */
911 #ifdef DYNA_DEBUG
912 fdprintf(fd,"LD D,B\n");
913 #endif
914 DYNA_MOVE_b_r_to_r(2,4);
915 break;
916 case 0x51: /* LD D,C */
917 #ifdef DYNA_DEBUG
918 fdprintf(fd,"LD D,C\n");
919 #endif
920 DYNA_MOVE_b_r_to_r(3,4);
921 break;
922 case 0x52: /* LD D,D */
923 break;
924 case 0x53: /* LD D,E */
925 #ifdef DYNA_DEBUG
926 fdprintf(fd,"LD D,E\n");
927 #endif
928 DYNA_MOVE_b_r_to_r(5,4);
929 break;
930 case 0x54: /* LD D,H */
931 #ifdef DYNA_DEBUG
932 fdprintf(fd,"LD D,H\n");
933 #endif
934 GETUPPER(6,0);
935 DYNA_MOVE_b_r_to_r(0,4);
936 break;
937 case 0x55: /* LD D,L */
938 #ifdef DYNA_DEBUG
939 fdprintf(fd,"LD D,L\n");
940 #endif
941 DYNA_MOVE_b_r_to_r(6,4);
942 break;
943 case 0x56: /* LD D,(HL) */
944 #ifdef DYNA_DEBUG
945 fdprintf(fd, "LD D,(HL)\n");
946 #endif
947 break; /* FIXME: Implement */
948 case 0x57: /* LD D,A */
949 #ifdef DYNA_DEBUG
950 fdprintf(fd,"LD D,A\n");
951 #endif
952 DYNA_MOVE_b_r_to_r(1,4);
953 break;
954 case 0x58: /* LD E,B */
955 #ifdef DYNA_DEBUG
956 fdprintf(fd,"LD E,B\n");
957 #endif
958 DYNA_MOVE_b_r_to_r(2,5);
959 break;
960 case 0x59: /* LD E,C */
961 #ifdef DYNA_DEBUG
962 fdprintf(fd,"LD E,C\n");
963 #endif
964 DYNA_MOVE_b_r_to_r(3,5);
965 break;
966 case 0x5A: /* LD E,D */
967 #ifdef DYNA_DEBUG
968 fdprintf(fd,"LD E,D\n");
969 #endif
970 DYNA_MOVE_b_r_to_r(4,5);
971 break;
972 case 0x5B: /* LD E,E */
973 break;
974 case 0x5C: /* LD E,H */
975 #ifdef DYNA_DEBUG
976 fdprintf(fd,"LD E,H\n");
977 #endif
978 GETUPPER(6,0);
979 DYNA_MOVE_b_r_to_r(0,5);
980 break;
981 case 0x5D: /* LD E,L */
982 #ifdef DYNA_DEBUG
983 fdprintf(fd,"LD E,L\n");
984 #endif
985 DYNA_MOVE_b_r_to_r(6,5);
986 break;
987 case 0x5E: /* LD E,(HL) */
988 #ifdef DYNA_DEBUG
989 fdprintf(fd, "LD E,(HL)\n");
990 #endif
991 break; /* FIXME: Implement */
992 case 0x5F: /* LD E,A */
993 #ifdef DYNA_DEBUG
994 fdprintf(fd,"LD E,A\n");
995 #endif
996 DYNA_MOVE_b_r_to_r(1,5);
997 break;
998 case 0x60: /* LD H,B */
999 #ifdef DYNA_DEBUG
1000 fdprintf(fd,"LD H,B\n");
1001 #endif
1002 DYNA_MOVE_b_r_to_r(2,0);
1003 PUTUPPER(0,6);
1004 break;
1005 case 0x61: /* LD H,C */
1006 #ifdef DYNA_DEBUG
1007 fdprintf(fd,"LD H,C\n");
1008 #endif
1009 DYNA_MOVE_b_r_to_r(3,0);
1010 PUTUPPER(0,6);
1011 break;
1012 case 0x62: /* LD H,D */
1013 #ifdef DYNA_DEBUG
1014 fdprintf(fd,"LD H,D\n");
1015 #endif
1016 DYNA_MOVE_b_r_to_r(4,0);
1017 PUTUPPER(0,6);
1018 break;
1019 case 0x63: /* LD H,E */
1020 #ifdef DYNA_DEBUG
1021 fdprintf(fd,"LD H,E\n");
1022 #endif
1023 DYNA_MOVE_b_r_to_r(5,0);
1024 PUTUPPER(0,6);
1025 break;
1026 case 0x64: /* LD H,H */
1027 break;
1028 case 0x65: /* LD H,L */
1029 #ifdef DYNA_DEBUG
1030 fdprintf(fd,"LD H,L\n");
1031 #endif
1032 DYNA_MOVE_b_r_to_r(6,0);
1033 PUTUPPER(0,6);
1034 break;
1035 case 0x66: /* LD H,(HL) */
1036 #ifdef DYNA_DEBUG
1037 fdprintf(fd, "LD H,(HL)\n");
1038 #endif
1039 break; /* FIXME: Implement */
1040 case 0x67: /* LD H,A */
1041 #ifdef DYNA_DEBUG
1042 fdprintf(fd,"LD H,A\n");
1043 #endif
1044 DYNA_MOVE_b_r_to_r(1,0);
1045 PUTUPPER(0,6);
1046 break;
1047 case 0x68: /* LD L,B */
1048 #ifdef DYNA_DEBUG
1049 fdprintf(fd,"LD L,B\n");
1050 #endif
1051 DYNA_MOVE_b_r_to_r(2,6);
1052 break;
1053 case 0x69: /* LD L,C */
1054 #ifdef DYNA_DEBUG
1055 fdprintf(fd,"LD L,C\n");
1056 #endif
1057 DYNA_MOVE_b_r_to_r(3,6);
1058 break;
1059 case 0x6A: /* LD L,D */
1060 #ifdef DYNA_DEBUG
1061 fdprintf(fd,"LD L,D\n");
1062 #endif
1063 DYNA_MOVE_b_r_to_r(4,6);
1064 break;
1065 case 0x6B: /* LD L,E */
1066 #ifdef DYNA_DEBUG
1067 fdprintf(fd,"LD L,E\n");
1068 #endif
1069 DYNA_MOVE_b_r_to_r(5,6);
1070 break;
1071 case 0x6C: /* LD L,H */
1072 #ifdef DYNA_DEBUG
1073 fdprintf(fd,"LD L,H\n");
1074 #endif
1075 GETUPPER(6,0);
1076 DYNA_MOVE_b_r_to_r(0,6);
1077 break;
1078 case 0x6D: /* LD L,L */
1079 break;
1080 case 0x6E: /* LD L,(HL) */
1081 #ifdef DYNA_DEBUG
1082 fdprintf(fd, "LD L,(HL)\n");
1083 #endif
1084 break; /* FIXME: Implement */
1085 case 0x6F: /* LD L,A */
1086 #ifdef DYNA_DEBUG
1087 fdprintf(fd, "LD L,A\n");
1088 #endif
1089 break; /* FIXME: Implement */
1090 case 0x70: /* LD (HL),B */
1091 #ifdef DYNA_DEBUG
1092 fdprintf(fd, "LD (HL),B\n");
1093 #endif
1094 break; /* FIXME: Implement */
1095 case 0x71: /* LD (HL),C */
1096 #ifdef DYNA_DEBUG
1097 fdprintf(fd, "LD (HL),C\n");
1098 #endif
1099 break; /* FIXME: Implement */
1100 case 0x72: /* LD (HL),D */
1101 #ifdef DYNA_DEBUG
1102 fdprintf(fd, "LD (HL),D\n");
1103 #endif
1104 break; /* FIXME: Implement */
1105 case 0x73: /* LD (HL),E */
1106 #ifdef DYNA_DEBUG
1107 fdprintf(fd, "LD (HL),E\n");
1108 #endif
1109 break; /* FIXME: Implement */
1110 case 0x74: /* LD (HL),H */
1111 #ifdef DYNA_DEBUG
1112 fdprintf(fd, "LD (HL),H\n");
1113 #endif
1114 break; /* FIXME: Implement */
1115 case 0x75: /* LD (HL),L */
1116 #ifdef DYNA_DEBUG
1117 fdprintf(fd, "LD (HL),L\n");
1118 #endif
1119 break; /* FIXME: Implement */
1120 case 0x76: /* HALT */
1121 #ifdef DYNA_DEBUG
1122 fdprintf(fd, "HALT\n");
1123 #endif
1124 break; /* FIXME: Implement */
1125 case 0x77: /* LD (HL),A */
1126 #ifdef DYNA_DEBUG
1127 fdprintf(fd, "LD (HL),A\n");
1128 #endif
1129 break; /* FIXME: Implement */
1130 case 0x78: /* LD A,B */
1131 #ifdef DYNA_DEBUG
1132 fdprintf(fd,"LD A,B\n");
1133 #endif
1134 DYNA_MOVE_b_r_to_r(2,1);
1135 break;
1136 case 0x79: /* LD A,C */
1137 #ifdef DYNA_DEBUG
1138 fdprintf(fd,"LD A,C\n");
1139 #endif
1140 DYNA_MOVE_b_r_to_r(3,1);
1141 break;
1142 case 0x7A: /* LD A,D */
1143 #ifdef DYNA_DEBUG
1144 fdprintf(fd,"LD A,D\n");
1145 #endif
1146 DYNA_MOVE_b_r_to_r(4,1);
1147 break;
1148 case 0x7B: /* LD A,E */
1149 #ifdef DYNA_DEBUG
1150 fdprintf(fd,"LD A,E\n");
1151 #endif
1152 DYNA_MOVE_b_r_to_r(5,1);
1153 break;
1154 case 0x7C: /* LD A,H */
1155 #ifdef DYNA_DEBUG
1156 fdprintf(fd,"LD A,H\n");
1157 #endif
1158 GETUPPER(5,0);
1159 DYNA_MOVE_b_r_to_r(0,1);
1160 break;
1161 case 0x7D: /* LD A,L */
1162 #ifdef DYNA_DEBUG
1163 fdprintf(fd,"LD A,L\n");
1164 #endif
1165 DYNA_MOVE_b_r_to_r(5,1);
1166 break;
1167 case 0x7E: /* LD A,HL */
1168 #ifdef DYNA_DEBUG
1169 fdprintf(fd, "LD A,HL\n");
1170 #endif
1171 break; /* FIXME: Implement */
1172 case 0x7F: /* LD A,A */
1173 break;
1174 case 0x80: /* ADD A,B */
1175 #ifdef DYNA_DEBUG
1176 fdprintf(fd, "ADD A,B\n");
1177 #endif
1178 break; /* FIXME: Implement */
1179 case 0x81: /* ADD A,C */
1180 #ifdef DYNA_DEBUG
1181 fdprintf(fd, "ADD A,C\n");
1182 #endif
1183 break; /* FIXME: Implement */
1184 case 0x82: /* ADD A,D */
1185 #ifdef DYNA_DEBUG
1186 fdprintf(fd, "ADD A,D\n");
1187 #endif
1188 break; /* FIXME: Implement */
1189 case 0x83: /* ADD A,E */
1190 #ifdef DYNA_DEBUG
1191 fdprintf(fd, "ADD A,E\n");
1192 #endif
1193 break; /* FIXME: Implement */
1194 case 0x84: /* ADD A,H */
1195 #ifdef DYNA_DEBUG
1196 fdprintf(fd, "ADD A,H\n");
1197 #endif
1198 break; /* FIXME: Implement */
1199 case 0x85: /* ADD A,L */
1200 #ifdef DYNA_DEBUG
1201 fdprintf(fd, "ADD A,L\n");
1202 #endif
1203 break; /* FIXME: Implement */
1204 case 0x86: /* ADD A,(HL) */
1205 #ifdef DYNA_DEBUG
1206 fdprintf(fd, "ADD A,(HL)\n");
1207 #endif
1208 break; /* FIXME: Implement */
1209 case 0x87: /* ADD A,A */
1210 #ifdef DYNA_DEBUG
1211 fdprintf(fd,"ADD A,A\n");
1212 #endif
1213 /* code taken from gcc -O3 output by compiling;
1214 * c=(2*b)&0xFF;
1215 * a=(c) ? 0 : 0x80 | zero flag
1216 * (0x20 & (c) << 1) | halfcarry
1217 * ((2*b)&0x100)>>4; carry
1219 DYNA_MOVE_l_r_to_r(1,0,0); /* move.l d1, d0 */
1220 DYNA_ADD_l_r_to_r(0,0,0); /* add.l d0, d0 */
1221 DYNA_AND_l_i_to_r(510,0); /* and.l #510, d0 */
1222 DYNA_MOVEA_l_r_to_r(0,3,0); /* movea.l d0,a3 */
1223 DYNA_CLR_b_r(7); /* clr.b d7 */
1224 DYNA_TST_b_r(0,0); /* tst.b d0 */
1225 DYNA_DUMMYBRANCH(2,0);
1226 DYNA_MOVE_l_r_to_r(1,0,0); /* move.l d1,d0 */
1227 DYNA_LSHIFT_l(3,0,0,0); /* lsr.l #3, d0 */
1228 DYNA_MOVEQ_l_i_to_r(16,1); /* moveq #16,d1 */
1229 DYNA_AND_l_r_to_r(1,0); /* and.l d1 d0 */
1230 DYNA_MOVEQ_l_i_to_r(0x80,7); /* moveq #0x80,d7 */
1231 DYNA_OR_l_r_to_r(0,7); /* or.l d0, d7 */
1232 DYNA_BCC_c(0x6,2,0); /* branch not equal, here */
1233 DYNA_MOVE_l_r_to_r(3,1,1); /* move.l a3,d1 */
1234 DYNA_AND_l_i_to_r(0xFE,1); /* and.l #0xFE,d1 */
1235 DYNA_AND_l_i_to_r(0xB0,7); /* and.l #0xB0,d7 */
1236 break;
1237 case 0x88: /* ADC A,B */
1238 #ifdef DYNA_DEBUG
1239 fdprintf(fd, "ADC A,B\n");
1240 #endif
1241 break; /* FIXME: Implement */
1242 case 0x89: /* ADC A,C */
1243 #ifdef DYNA_DEBUG
1244 fdprintf(fd, "ADC A,C\n");
1245 #endif
1246 break; /* FIXME: Implement */
1247 case 0x8A: /* ADC A,D */
1248 #ifdef DYNA_DEBUG
1249 fdprintf(fd, "ADC A,D\n");
1250 #endif
1251 break; /* FIXME: Implement */
1252 case 0x8B: /* ADC A,E */
1253 #ifdef DYNA_DEBUG
1254 fdprintf(fd, "ADC A,E\n");
1255 #endif
1256 break; /* FIXME: Implement */
1257 case 0x8C: /* ADC A,H */
1258 #ifdef DYNA_DEBUG
1259 fdprintf(fd, "ADC A,H\n");
1260 #endif
1261 break; /* FIXME: Implement */
1262 case 0x8D: /* ADC A,L */
1263 #ifdef DYNA_DEBUG
1264 fdprintf(fd, "ADC A,L\n");
1265 #endif
1266 break; /* FIXME: Implement */
1267 case 0x8E: /* ADC A,(HL) */
1268 #ifdef DYNA_DEBUG
1269 fdprintf(fd, "ADC A,(HL)\n");
1270 #endif
1271 break; /* FIXME: Implement */
1272 case 0x8F: /* ADC A */
1273 #ifdef DYNA_DEBUG
1274 fdprintf(fd, "ADC A\n");
1275 #endif
1276 break; /* FIXME: Implement */
1277 case 0x90: /* SUB B */
1278 #ifdef DYNA_DEBUG
1279 fdprintf(fd, "SUB B\n");
1280 #endif
1281 break; /* FIXME: Implement */
1282 case 0x91: /* SUB C */
1283 #ifdef DYNA_DEBUG
1284 fdprintf(fd, "SUB C\n");
1285 #endif
1286 break; /* FIXME: Implement */
1287 case 0x92: /* SUB D */
1288 #ifdef DYNA_DEBUG
1289 fdprintf(fd, "SUB D\n");
1290 #endif
1291 break; /* FIXME: Implement */
1292 case 0x93: /* SUB E */
1293 #ifdef DYNA_DEBUG
1294 fdprintf(fd, "SUB E\n");
1295 #endif
1296 break; /* FIXME: Implement */
1297 case 0x94: /* SUB H */
1298 #ifdef DYNA_DEBUG
1299 fdprintf(fd, "SUB H\n");
1300 #endif
1301 break; /* FIXME: Implement */
1302 case 0x95: /* SUB L */
1303 #ifdef DYNA_DEBUG
1304 fdprintf(fd, "SUB L\n");
1305 #endif
1306 break; /* FIXME: Implement */
1307 case 0x96: /* SUB (HL) */
1308 #ifdef DYNA_DEBUG
1309 fdprintf(fd, "SUB (HL)\n");
1310 #endif
1311 break; /* FIXME: Implement */
1312 case 0x97: /* SUB A (halfcarry ?) */
1313 #ifdef DYNA_DEBUG
1314 fdprintf(fd,"SUB A\n");
1315 #endif
1316 DYNA_CLR_l_r(1);
1317 DYNA_MOVEQ_l_i_to_r(0xC0,7);
1318 break;
1319 case 0x98: /* SBC A,B */
1320 #ifdef DYNA_DEBUG
1321 fdprintf(fd, "SBC A,B\n");
1322 #endif
1323 break; /* FIXME: Implement */
1324 case 0x99: /* SBC A,C */
1325 #ifdef DYNA_DEBUG
1326 fdprintf(fd, "SBC A,C\n");
1327 #endif
1328 break; /* FIXME: Implement */
1329 case 0x9A: /* SBC A,D */
1330 #ifdef DYNA_DEBUG
1331 fdprintf(fd, "SBC A,D\n");
1332 #endif
1333 break; /* FIXME: Implement */
1334 case 0x9B: /* SBC A,E */
1335 #ifdef DYNA_DEBUG
1336 fdprintf(fd, "SBC A,E\n");
1337 #endif
1338 break; /* FIXME: Implement */
1339 case 0x9C: /* SBC A,H */
1340 #ifdef DYNA_DEBUG
1341 fdprintf(fd, "SBC A,H\n");
1342 #endif
1343 break; /* FIXME: Implement */
1344 case 0x9D: /* SBC A,L */
1345 #ifdef DYNA_DEBUG
1346 fdprintf(fd, "SBC A,L\n");
1347 #endif
1348 break; /* FIXME: Implement */
1349 case 0x9E: /* SBC A,(HL) */
1350 #ifdef DYNA_DEBUG
1351 fdprintf(fd, "SBC A,(HL)\n");
1352 #endif
1353 break; /* FIXME: Implement */
1354 case 0x9F: /* SBC A,A */
1355 #ifdef DYNA_DEBUG
1356 fdprintf(fd, "SBC A,A\n");
1357 #endif
1358 break; /* FIXME: Implement */
1359 case 0xA0: /* AND B */
1360 #ifdef DYNA_DEBUG
1361 fdprintf(fd, "AND B\n");
1362 #endif
1363 break; /* FIXME: Implement */
1364 case 0xA1: /* AND C */
1365 #ifdef DYNA_DEBUG
1366 fdprintf(fd, "AND C\n");
1367 #endif
1368 break; /* FIXME: Implement */
1369 case 0xA2: /* AND D */
1370 #ifdef DYNA_DEBUG
1371 fdprintf(fd, "AND D\n");
1372 #endif
1373 break; /* FIXME: Implement */
1374 case 0xA3: /* AND E */
1375 #ifdef DYNA_DEBUG
1376 fdprintf(fd, "AND E\n");
1377 #endif
1378 break; /* FIXME: Implement */
1379 case 0xA4: /* AND H */
1380 #ifdef DYNA_DEBUG
1381 fdprintf(fd, "AND H\n");
1382 #endif
1383 break; /* FIXME: Implement */
1384 case 0xA5: /* AND L */
1385 #ifdef DYNA_DEBUG
1386 fdprintf(fd, "AND L\n");
1387 #endif
1388 break; /* FIXME: Implement */
1389 case 0xA6: /* AND (HL) */
1390 #ifdef DYNA_DEBUG
1391 fdprintf(fd, "AND (HL)\n");
1392 #endif
1393 break; /* FIXME: Implement */
1394 case 0xA7: /* AND A */
1395 #ifdef DYNA_DEBUG
1396 fdprintf(fd, "AND A\n");
1397 #endif
1398 break; /* FIXME: Implement */
1399 case 0xA8: /* XOR B */
1400 #ifdef DYNA_DEBUG
1401 fdprintf(fd, "XOR B\n");
1402 #endif
1403 break; /* FIXME: Implement */
1404 case 0xA9: /* XOR C */
1405 #ifdef DYNA_DEBUG
1406 fdprintf(fd, "XOR C\n");
1407 #endif
1408 break; /* FIXME: Implement */
1409 case 0xAA: /* XOR D */
1410 #ifdef DYNA_DEBUG
1411 fdprintf(fd, "XOR D\n");
1412 #endif
1413 break; /* FIXME: Implement */
1414 case 0xAB: /* XOR E */
1415 #ifdef DYNA_DEBUG
1416 fdprintf(fd, "XOR E\n");
1417 #endif
1418 break; /* FIXME: Implement */
1419 case 0xAC: /* XOR H */
1420 #ifdef DYNA_DEBUG
1421 fdprintf(fd, "XOR H\n");
1422 #endif
1423 break; /* FIXME: Implement */
1424 case 0xAD: /* XOR L */
1425 #ifdef DYNA_DEBUG
1426 fdprintf(fd, "XOR L\n");
1427 #endif
1428 break; /* FIXME: Implement */
1429 case 0xAE: /* XOR (HL) */
1430 #ifdef DYNA_DEBUG
1431 fdprintf(fd, "XOR (HL)\n");
1432 #endif
1433 break; /* FIXME: Implement */
1434 case 0xAF: /* XOR A */
1435 #ifdef DYNA_DEBUG
1436 fdprintf(fd, "XOR A\n");
1437 #endif
1438 break; /* FIXME: Implement */
1439 case 0xB0: /* OR B */
1440 #ifdef DYNA_DEBUG
1441 fdprintf(fd, "OR B\n");
1442 #endif
1443 break; /* FIXME: Implement */
1444 case 0xB1: /* OR C */
1445 #ifdef DYNA_DEBUG
1446 fdprintf(fd, "OR C\n");
1447 #endif
1448 break; /* FIXME: Implement */
1449 case 0xB2: /* OR D */
1450 #ifdef DYNA_DEBUG
1451 fdprintf(fd, "OR D\n");
1452 #endif
1453 break; /* FIXME: Implement */
1454 case 0xB3: /* OR E */
1455 #ifdef DYNA_DEBUG
1456 fdprintf(fd, "OR E\n");
1457 #endif
1458 break; /* FIXME: Implement */
1459 case 0xB4: /* OR H */
1460 #ifdef DYNA_DEBUG
1461 fdprintf(fd, "OR H\n");
1462 #endif
1463 break; /* FIXME: Implement */
1464 case 0xB5: /* OR L */
1465 #ifdef DYNA_DEBUG
1466 fdprintf(fd, "OR L\n");
1467 #endif
1468 break; /* FIXME: Implement */
1469 case 0xB6: /* OR (HL) */
1470 #ifdef DYNA_DEBUG
1471 fdprintf(fd, "OR (HL)\n");
1472 #endif
1473 break; /* FIXME: Implement */
1474 case 0xB7: /* OR A */
1475 #ifdef DYNA_DEBUG
1476 fdprintf(fd, "OR A\n");
1477 #endif
1478 break; /* FIXME: Implement */
1479 case 0xB8: /* CP B */
1480 #ifdef DYNA_DEBUG
1481 fdprintf(fd, "CP B\n");
1482 #endif
1483 break; /* FIXME: Implement */
1484 case 0xB9: /* CP C */
1485 #ifdef DYNA_DEBUG
1486 fdprintf(fd, "CP C\n");
1487 #endif
1488 break; /* FIXME: Implement */
1489 case 0xBA: /* CP D */
1490 #ifdef DYNA_DEBUG
1491 fdprintf(fd, "CP D\n");
1492 #endif
1493 break; /* FIXME: Implement */
1494 case 0xBB: /* CP E */
1495 #ifdef DYNA_DEBUG
1496 fdprintf(fd, "CP E\n");
1497 #endif
1498 break; /* FIXME: Implement */
1499 case 0xBC: /* CP H */
1500 #ifdef DYNA_DEBUG
1501 fdprintf(fd, "CP H\n");
1502 #endif
1503 break; /* FIXME: Implement */
1504 case 0xBD: /* CP L */
1505 #ifdef DYNA_DEBUG
1506 fdprintf(fd, "CP L\n");
1507 #endif
1508 break; /* FIXME: Implement */
1509 case 0xBE: /* CP (HL) */
1510 #ifdef DYNA_DEBUG
1511 fdprintf(fd, "CP (HL)\n");
1512 #endif
1513 break; /* FIXME: Implement */
1514 case 0xBF: /* CP A */
1515 #ifdef DYNA_DEBUG
1516 fdprintf(fd, "CP A\n");
1517 #endif
1518 break; /* FIXME: Implement */
1519 case 0xC0: /* RET NZ */
1520 #ifdef DYNA_DEBUG
1521 fdprintf(fd, "RET NZ\n");
1522 #endif
1523 break; /* FIXME: Implement */
1524 case 0xC1: /* POP BC */
1525 #ifdef DYNA_DEBUG
1526 fdprintf(fd, "POP BC\n");
1527 #endif
1528 break;
1529 case 0xC2: /* JP NZ */
1530 #ifdef DYNA_DEBUG
1531 fdprintf(fd,"JP NZ\n");
1532 #endif
1533 DYNA_BTST_l_r(8,7); /* btst #8,d7 */
1534 DYNA_DUMMYBRANCH(2,0);
1535 DYNA_MOVEA_l_i_to_r(&blockclen,3);
1536 DYNA_MOVE_l_i_to_m(tclen,3);
1537 DYNA_MOVEA_l_i_to_r(readw(PC),1);
1538 DYNA_RET();
1539 DYNA_BCC_c(0x6,2,0); /* jump here if bit is not zero */
1540 tclen--;
1541 PC+=2;
1542 break;
1543 case 0xC3: /* JP (imm) PC = readw(PC) */
1544 #ifdef DYNA_DEBUG
1545 fdprintf(fd,"JP (0x%x)\n",readw(xPC));
1546 #endif
1547 PC=readw(PC);
1548 done=1;
1549 break;
1550 case 0xC4: /* CALL NZ */
1551 #ifdef DYNA_DEBUG
1552 fdprintf(fd, "CALL NZ\n");
1553 #endif
1554 break; /* FIXME: Implement */
1555 case 0xC5: /* PUSH BC */
1556 #ifdef DYNA_DEBUG
1557 fdprintf(fd, "PUSH BC\n");
1558 #endif
1559 break; /* FIXME: Implement */
1560 case 0xC6: /* ADD A,imm */
1561 #ifdef DYNA_DEBUG
1562 fdprintf(fd, "ADD A,imm\n");
1563 #endif
1564 break; /* FIXME: Implement */
1565 case 0xC7: /* RST 0h */
1566 #ifdef DYNA_DEBUG
1567 fdprintf(fd, "RST 0h\n");
1568 #endif
1569 break; /* FIXME: Implement */
1570 case 0xC8: /* RET Z */
1571 #ifdef DYNA_DEBUG
1572 fdprintf(fd, "RET Z\n");
1573 #endif
1574 break; /* FIXME: Implement */
1575 case 0xC9: /* RET */
1576 #ifdef DYNA_DEBUG
1577 fdprintf(fd,"RET\n");
1578 #endif
1579 POPA(1);
1580 writepc=0;
1581 done=1;
1582 break;
1583 case 0xCA: /* JP Z */
1584 break; /* FIXME: Implement */
1585 case 0xCB: /* NULL */
1586 #ifdef DYNA_DEBUG
1587 fdprintf(fd,"NULL\n");
1588 #endif
1589 break;
1590 case 0xCC: /* CALL Z */
1591 #ifdef DYNA_DEBUG
1592 fdprintf(fd, "CALL Z\n");
1593 #endif
1594 break; /* FIXME: Implement */
1595 case 0xCD: /* CALL (imm) PUSH(PC+2) PC=readw(PC); */
1596 #ifdef DYNA_DEBUG
1597 fdprintf(fd,"CALL (0x%x)\n",readw(xPC));
1598 #endif
1599 PUSH(PC+2);
1600 PC=readw(PC);
1601 done=1;
1602 break;
1603 case 0xCE: /* ADC A,imm */
1604 #ifdef DYNA_DEBUG
1605 fdprintf(fd, "ADC A,imm\n");
1606 #endif
1607 break; /* FIXME: Implement */
1608 case 0xCF: /* RST 8h */
1609 #ifdef DYNA_DEBUG
1610 fdprintf(fd, "RST 8h\n");
1611 #endif
1612 break; /* FIXME: Implement */
1613 case 0xD0: /* RET NC */
1614 #ifdef DYNA_DEBUG
1615 fdprintf(fd,"RET NC\n");
1616 #endif
1617 DYNA_BTST_l_r(5,7); /* btst #5,d7 */
1618 DYNA_DUMMYBRANCH(2,0);
1619 POPA(1); /* POP %a1 */
1620 DYNA_MOVEA_l_i_to_r(&blockclen,3);
1621 DYNA_MOVE_l_i_to_m(tclen,3);
1622 DYNA_RET();
1623 DYNA_BCC_c(0x6,2,0); /* jump here if bit is not zero */
1624 tclen-=3;
1625 break;
1626 case 0xD1: /* POP DE */
1627 #ifdef DYNA_DEBUG
1628 fdprintf(fd, "POP DE\n");
1629 #endif
1630 break; /* FIXME: Implement */
1631 case 0xD2: /* JP NC */
1632 #ifdef DYNA_DEBUG
1633 fdprintf(fd, "JP NC\n");
1634 #endif
1635 break; /* FIXME: Implement */
1636 case 0xD3: /* NULL */
1637 #ifdef DYNA_DEBUG
1638 fdprintf(fd,"NULL\n");
1639 #endif
1640 break;
1641 case 0xD4: /* CALL NC */
1642 #ifdef DYNA_DEBUG
1643 fdprintf(fd, "CALL NC\n");
1644 #endif
1645 break; /* FIXME: Implement */
1646 case 0xD5: /* PUSH DE */
1647 #ifdef DYNA_DEBUG
1648 fdprintf(fd, "PUSH DE\n");
1649 #endif
1650 break; /* FIXME: Implement */
1651 case 0xD6: /* SUB imm */
1652 #ifdef DYNA_DEBUG
1653 fdprintf(fd, "SUB imm\n");
1654 #endif
1655 break; /* FIXME: Implement */
1656 case 0xD7: /* RST 10h */
1657 #ifdef DYNA_DEBUG
1658 fdprintf(fd, "RST 10h\n");
1659 #endif
1660 break; /* FIXME: Implement */
1661 case 0xD8: /* RET C */
1662 #ifdef DYNA_DEBUG
1663 fdprintf(fd, "RET C\n");
1664 #endif
1665 break; /* FIXME: Implement */
1666 case 0xD9: /* RETI */
1667 #ifdef DYNA_DEBUG
1668 fdprintf(fd, "RETI\n");
1669 #endif
1670 break; /* FIXME: Implement */
1671 case 0xDA: /* JP C */
1672 #ifdef DYNA_DEBUG
1673 fdprintf(fd, "JP C\n");
1674 #endif
1675 break; /* FIXME: Implement */
1676 case 0xDB: /* NULL */
1677 #ifdef DYNA_DEBUG
1678 fdprintf(fd,"NULL\n");
1679 #endif
1680 break;
1681 case 0xDC: /* CALL NC */
1682 #ifdef DYNA_DEBUG
1683 fdprintf(fd, "CALL NC\n");
1684 #endif
1685 break; /* FIXME: Implement */
1686 case 0xDD: /* NULL */
1687 #ifdef DYNA_DEBUG
1688 fdprintf(fd,"NULL\n");
1689 #endif
1690 break;
1691 case 0xDE: /* SBC A,imm */
1692 #ifdef DYNA_DEBUG
1693 fdprintf(fd, "SBC A,imm\n");
1694 #endif
1695 break; /* FIXME: Implement */
1696 case 0xDF: /* RST 18h */
1697 #ifdef DYNA_DEBUG
1698 fdprintf(fd, "RST 18h\n");
1699 #endif
1700 break; /* FIXME: Implement */
1701 case 0xE0: /* LDH (imm),A */
1702 #ifdef DYNA_DEBUG
1703 fdprintf(fd,"LD (0x%x),A\n",readb(xPC));
1704 #endif
1705 DYNA_PUSH_l_r(1,0);
1706 DYNA_PEA_w_i(FETCH);
1707 CALL_NATIVE(&writehi);
1708 DYNA_ADDQ_l_i_to_r(0,7,1);
1709 /*writehi(FETCH, A); */
1710 break;
1711 case 0xE1: /* POP HL */
1712 #ifdef DYNA_DEBUG
1713 fdprintf(fd, "POP HL\n");
1714 #endif
1715 break; /* FIXME: Implement */
1716 case 0xE2: /* LDH (imm),A */
1717 #ifdef DYNA_DEBUG
1718 fdprintf(fd, "LDH (imm),A\n");
1719 #endif
1720 break; /* FIXME: Implement */
1721 case 0xE3: /* NULL */
1722 #ifdef DYNA_DEBUG
1723 fdprintf(fd,"NULL\n");
1724 #endif
1725 break;
1726 case 0xE4: /* NULL */
1727 break;
1728 #ifdef DYNA_DEBUG
1729 fdprintf(fd,"NULL\n");
1730 #endif
1731 case 0xE5: /* PUSH HL */
1732 #ifdef DYNA_DEBUG
1733 fdprintf(fd, "PUSH HL\n");
1734 #endif
1735 break; /* FIXME: Implement */
1736 case 0xE6: /* AND imm */
1737 #ifdef DYNA_DEBUG
1738 fdprintf(fd, "AND imm\n");
1739 #endif
1740 break; /* FIXME: Implement */
1741 case 0xE7: /* RST 20h */
1742 #ifdef DYNA_DEBUG
1743 fdprintf(fd, "RST 20h\n");
1744 #endif
1745 break; /* FIXME: Implement */
1746 case 0xE8: /* ADD SP */
1747 #ifdef DYNA_DEBUG
1748 fdprintf(fd, "ADD SP\n");
1749 #endif
1750 break; /* FIXME: Implement */
1751 case 0xE9: /* JP HL */
1752 #ifdef DYNA_DEBUG
1753 fdprintf(fd, "JP HL\n");
1754 #endif
1755 break; /* FIXME: Implement */
1756 case 0xEA: /* LD A */
1757 #ifdef DYNA_DEBUG
1758 fdprintf(fd, "LD A\n");
1759 #endif
1760 break; /* FIXME: Implement */
1761 case 0xEB: /* NULL */
1762 #ifdef DYNA_DEBUG
1763 fdprintf(fd,"NULL\n");
1764 #endif
1765 break;
1766 case 0xEC: /* NULL */
1767 #ifdef DYNA_DEBUG
1768 fdprintf(fd,"NULL\n");
1769 #endif
1770 break;
1771 case 0xED: /* NULL */
1772 #ifdef DYNA_DEBUG
1773 fdprintf(fd,"NULL\n");
1774 #endif
1775 break;
1776 case 0xEE: /* XOR imm */
1777 #ifdef DYNA_DEBUG
1778 fdprintf(fd, "XOR imm\n");
1779 #endif
1780 break; /* FIXME: Implement */
1781 case 0xEF: /* RST 28h */
1782 #ifdef DYNA_DEBUG
1783 fdprintf(fd, "RST 28h\n");
1784 #endif
1785 break; /* FIXME: Implement */
1786 case 0xF0: /* LDH A,(imm) */
1787 #ifdef DYNA_DEBUG
1788 fdprintf(fd,"LDH A,(0x%x)\n",readb(xPC));
1789 #endif
1790 DYNA_PEA_w_i(FETCH);
1791 CALL_NATIVE(&readhi);
1792 DYNA_ADDQ_l_i_to_r(4,7,1);
1793 DYNA_MOVE_b_r_to_r(0,1);
1794 /*A = readhi(FETCH)*/
1795 break;
1796 case 0xF1: /* POP AF */
1797 #ifdef DYNA_DEBUG
1798 fdprintf(fd, "POP AF\n");
1799 #endif
1800 break; /* FIXME: Implement */
1801 case 0xF2: /* LDH A,(imm) */
1802 #ifdef DYNA_DEBUG
1803 fdprintf(fd, "LDH A,(imm)\n");
1804 #endif
1805 break; /* FIXME: Implement */
1806 case 0xF3: /* DI */
1807 #ifdef DYNA_DEBUG
1808 fdprintf(fd,"DI\n");
1809 #endif
1810 DYNA_CLR_l_m(&cpu.ime);
1811 DYNA_CLR_l_m(&cpu.ima);
1812 DYNA_CLR_l_m(&cpu.halt);
1813 /* cpu.halt = cpu.ima = cpu.ime = 0; */
1814 break;
1815 case 0xF4: /* NULL */
1816 #ifdef DYNA_DEBUG
1817 fdprintf(fd,"NULL\n");
1818 #endif
1819 break;
1820 case 0xF5: /* PUSH AF */
1821 #ifdef DYNA_DEBUG
1822 fdprintf(fd, "PUSH AF\n");
1823 #endif
1824 break; /* FIXME: Implement */
1825 case 0xF6: /* OR imm */
1826 #ifdef DYNA_DEBUG
1827 fdprintf(fd, "OR imm\n");
1828 #endif
1829 break; /* FIXME: Implement */
1830 case 0xF7: /* RST 30h */
1831 #ifdef DYNA_DEBUG
1832 fdprintf(fd, "RST 30h\n");
1833 #endif
1834 break; /* FIXME: Implement */
1835 case 0xF8: /* LD HL,SP */
1836 #ifdef DYNA_DEBUG
1837 fdprintf(fd, "LD HL,SP\n");
1838 #endif
1839 break; /* FIXME: Implement */
1840 case 0xF9: /* LD SP,HL */
1841 #ifdef DYNA_DEBUG
1842 fdprintf(fd,"LD SP,HL\n");
1843 #endif
1844 DYNA_MOVEA_w_r_to_r(6,0,0);
1845 break;
1846 case 0xFA: /* LD A, (imm) */
1847 #ifdef DYNA_DEBUG
1848 fdprintf(fd,"LD A,(0x%x)\n",readw(xPC));
1849 #endif
1850 /*DYNA_PEA_w_i(readw(xPC));
1851 PC+=2; \
1852 CALL_NATIVE(&readb); \
1853 DYNA_ADDQ_l_i_to_r(4,7,1); \
1854 DYNA_MOVE_l_r_to_r(0,1,0);*/
1855 break;
1856 case 0xFB: /* EI */
1857 #ifdef DYNA_DEBUG
1858 fdprintf(fd,"EI\n");
1859 #endif
1860 DYNA_MOVEQ_l_i_to_r(1,0);
1861 DYNA_MOVEA_l_i_to_r(&cpu.ima,3);
1862 DYNA_MOVE_l_r_to_m(0,3);
1863 /*cpu.ima=1; */
1864 break;
1865 case 0xFC: /* NULL */
1866 #ifdef DYNA_DEBUG
1867 fdprintf(fd,"NULL\n");
1868 #endif
1869 break;
1870 case 0xFD: /* NULL */
1871 #ifdef DYNA_DEBUG
1872 fdprintf(fd,"NULL\n");
1873 #endif
1874 break;
1875 case 0xFE: /* CMP #<imm> TODO: can be (much) more efficient.*/
1876 #ifdef DYNA_DEBUG
1877 fdprintf(fd,"CMP #0x%x\n",readb(xPC));
1878 #endif
1879 DYNA_MOVEA_l_r_to_r(2,3,0); /* movea.l %d2, %a3 */
1880 DYNA_MOVEQ_l_i_to_r(FETCH,2); /* moveq.l #<FETCH>,%d2 */
1881 CMP(2);
1882 DYNA_MOVE_l_r_to_r(3,2,1); /* move.l %a3, %d2 */
1883 break;
1884 case 0xFF: /* RST 38h */
1885 #ifdef DYNA_DEBUG
1886 fdprintf(fd, "RST 38h\n");
1887 #endif
1888 break; /* FIXME: Implement */
1889 default:
1890 snprintf(meow,499,"unimplemented opcode %d / 0x%x",op,op);
1891 die(meow);
1892 return;
1893 break;
1896 #ifdef DYNA_DEBUG
1897 fdprintf(fd,"(End of Block)\n");
1898 close(fd);
1899 #endif
1900 DYNA_MOVEA_l_i_to_r(&blockclen,3);
1901 DYNA_MOVE_l_i_to_m(tclen,3);
1902 if(writepc)
1903 DYNA_MOVEA_l_i_to_r(PC,1);
1904 DYNA_RET();
1905 PC=oldpc;
1906 setmallocpos(dynapointer);
1907 newblock->length=dynapointer-newblock->block;
1908 IF_COP(rb->cpucache_invalidate());
1909 snprintf(meow,499,"/dyna_0x%x_code.rb",PC);
1910 fd=open(meow,O_WRONLY|O_CREAT|O_TRUNC, 0666);
1911 if(fd>=0)
1913 write(fd,newblock->block,newblock->length);
1914 close(fd);