summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichiel Van Der Kolk <not.valid@email.address>2005-03-05 19:42:22 +0000
committerMichiel Van Der Kolk <not.valid@email.address>2005-03-05 19:42:22 +0000
commit12ab0ab36aa4ef13d71026c63bee36dbfc012f14 (patch)
tree48fe539081b0b135b0cfebff8ae3d5471adb76c4
parentd1f948423e77418206185d39e5f4f17e19602f62 (diff)
downloadrockbox-12ab0ab36aa4ef13d71026c63bee36dbfc012f14.tar.gz
rockbox-12ab0ab36aa4ef13d71026c63bee36dbfc012f14.zip
Dynarec debug system added - creates various debugging files in the root.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6142 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/rockboy/cpu.c7
-rw-r--r--apps/plugins/rockboy/dynarec.c336
2 files changed, 286 insertions, 57 deletions
diff --git a/apps/plugins/rockboy/cpu.c b/apps/plugins/rockboy/cpu.c
index 1ed62cab92..656341aaac 100644
--- a/apps/plugins/rockboy/cpu.c
+++ b/apps/plugins/rockboy/cpu.c
@@ -242,7 +242,7 @@ un32 reg_backup[16];
242struct dynarec_block *address_map[1<<HASH_SIGNIFICANT_LOWER_BITS]; 242struct dynarec_block *address_map[1<<HASH_SIGNIFICANT_LOWER_BITS];
243extern void *dynapointer; 243extern void *dynapointer;
244int blockcount; 244int blockcount;
245#define MAXBLOCK 10 245#define MAXBLOCK 6
246#endif 246#endif
247 247
248 248
@@ -948,11 +948,10 @@ next:
948 if(b) { // call block 948 if(b) { // call block
949 int fd; 949 int fd;
950 blockcount++; 950 blockcount++;
951 snprintf(meow,499,"/dyna_0x%x.rb",PC); 951 snprintf(meow,499,"/dyna_0x%x_run.rb",PC);
952 fd=open(meow,O_WRONLY|O_CREAT); 952 fd=open(meow,O_WRONLY|O_CREAT);
953 if(fd>=0) { 953 if(fd>=0) {
954 fdprintf(fd,"Block 0x%x\n",PC); 954 fdprintf(fd,"Block 0x%x Blockcount: %d\n",PC,blockcount);
955 write(fd,b->block,b->length);
956 fdprintf(fd,"before: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", 955 fdprintf(fd,"before: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
957 cpu.a,cpu.b,cpu.c,cpu.d,cpu.e,cpu.hl,cpu.f,cpu.sp,cpu.pc, 956 cpu.a,cpu.b,cpu.c,cpu.d,cpu.e,cpu.hl,cpu.f,cpu.sp,cpu.pc,
958 cpu.ime); 957 cpu.ime);
diff --git a/apps/plugins/rockboy/dynarec.c b/apps/plugins/rockboy/dynarec.c
index b4f420d6c8..f9f7ebdfc7 100644
--- a/apps/plugins/rockboy/dynarec.c
+++ b/apps/plugins/rockboy/dynarec.c
@@ -14,6 +14,8 @@
14void *dynapointer,*branchp[10]; 14void *dynapointer,*branchp[10];
15int blockclen; 15int blockclen;
16 16
17#define DYNA_DEBUG 1
18
17#define DWRITEB(a) *((unsigned char *) dynapointer)=(a); dynapointer+=1 19#define DWRITEB(a) *((unsigned char *) dynapointer)=(a); dynapointer+=1
18#define DWRITEW(a) *((unsigned short *) dynapointer)=(a); dynapointer+=2 20#define DWRITEW(a) *((unsigned short *) dynapointer)=(a); dynapointer+=2
19#define DWRITEL(a) *((unsigned long *) dynapointer)=(a); dynapointer+=4 21#define DWRITEL(a) *((unsigned long *) dynapointer)=(a); dynapointer+=4
@@ -372,7 +374,7 @@ void DYNA_DEC_l_r(un8 dest,int is_areg) {
372 374
373 375
374void dynamic_recompile (struct dynarec_block *newblock) { 376void dynamic_recompile (struct dynarec_block *newblock) {
375 int done=0,writepc=1; 377 int done=0,writepc=1,fd;
376 byte op; 378 byte op;
377 unsigned int oldpc=PC; 379 unsigned int oldpc=PC;
378 unsigned short temp; 380 unsigned short temp;
@@ -380,7 +382,14 @@ void dynamic_recompile (struct dynarec_block *newblock) {
380 char meow[500]; 382 char meow[500];
381 dynapointer=malloc(512); 383 dynapointer=malloc(512);
382 newblock->block=dynapointer; 384 newblock->block=dynapointer;
383 385#ifdef DYNA_DEBUG
386 snprintf(meow,499,"/dyna_0x%x_asm.rb",PC);
387 fd=open(meow,O_WRONLY|O_CREAT);
388 if(fd<0) {
389 die("couldn't open dyna debug file");
390 return;
391 }
392#endif
384 snprintf(meow,499,"Recompiling 0x%x",oldpc); 393 snprintf(meow,499,"Recompiling 0x%x",oldpc);
385 rb->splash(HZ*1,1,meow); 394 rb->splash(HZ*1,1,meow);
386 while(!done) { 395 while(!done) {
@@ -399,6 +408,9 @@ void dynamic_recompile (struct dynarec_block *newblock) {
399 break; 408 break;
400 409
401 case 0x0B: /* DEC BC* 410 case 0x0B: /* DEC BC*
411#ifdef DYNA_DEBUG
412 fdprintf(fd,"DEC BC\n");
413#endif
402 DYNA_TST_b_r(3); // test C 414 DYNA_TST_b_r(3); // test C
403 DYNA_DUMMYBRANCH(2,0); 415 DYNA_DUMMYBRANCH(2,0);
404 DYNA_DEC_l_r(2,0); // dec B 416 DYNA_DEC_l_r(2,0); // dec B
@@ -406,154 +418,284 @@ void dynamic_recompile (struct dynarec_block *newblock) {
406 DYNA_DEC_l_r(3,0); // dec C 418 DYNA_DEC_l_r(3,0); // dec C
407 break; 419 break;
408 case 0x41: /* LD B,C */ 420 case 0x41: /* LD B,C */
421#ifdef DYNA_DEBUG
422 fdprintf(fd,"LD B,C\n");
423#endif
409 DYNA_MOVE_b_r_to_r(3,2); 424 DYNA_MOVE_b_r_to_r(3,2);
410 break; 425 break;
411 case 0x42: /* LD B,D */ 426 case 0x42: /* LD B,D */
427#ifdef DYNA_DEBUG
428 fdprintf(fd,"LD B,D\n");
429#endif
412 DYNA_MOVE_b_r_to_r(4,2); 430 DYNA_MOVE_b_r_to_r(4,2);
413 break; 431 break;
414 case 0x43: /* LD B,E */ 432 case 0x43: /* LD B,E */
415 DYNA_MOVE_b_r_to_r(5,2); 433#ifdef DYNA_DEBUG
434 fdprintf(fd,"LD B,E\n");
435#endif
436 DYNA_MOVE_b_r_to_r(5,2);
416 break; 437 break;
417 case 0x44: /* LD B,H */ 438 case 0x44: /* LD B,H */
418 GETUPPER(6,0); 439#ifdef DYNA_DEBUG
440 fdprintf(fd,"LD B,H\n");
441#endif
442 GETUPPER(6,0);
419 DYNA_MOVE_b_r_to_r(0,2); 443 DYNA_MOVE_b_r_to_r(0,2);
420 break; 444 break;
421 case 0x45: /* LD B,L */ 445 case 0x45: /* LD B,L */
422 DYNA_MOVE_b_r_to_r(6,2); 446#ifdef DYNA_DEBUG
447 fdprintf(fd,"LD B,L\n");
448#endif
449 DYNA_MOVE_b_r_to_r(6,2);
423 break; 450 break;
424 case 0x47: /* LD B,A */ 451 case 0x47: /* LD B,A */
425 DYNA_MOVE_b_r_to_r(1,2); 452#ifdef DYNA_DEBUG
453 fdprintf(fd,"LD B,A\n");
454#endif
455 DYNA_MOVE_b_r_to_r(1,2);
426 break; 456 break;
427 case 0x48: /* LD C,B */ 457 case 0x48: /* LD C,B */
428 DYNA_MOVE_b_r_to_r(2,3); 458#ifdef DYNA_DEBUG
459 fdprintf(fd,"LD C,B\n");
460#endif
461 DYNA_MOVE_b_r_to_r(2,3);
429 break; 462 break;
430 case 0x4A: /* LD C,D */ 463 case 0x4A: /* LD C,D */
431 DYNA_MOVE_b_r_to_r(4,3); 464#ifdef DYNA_DEBUG
465 fdprintf(fd,"LD C,D\n");
466#endif
467 DYNA_MOVE_b_r_to_r(4,3);
432 break; 468 break;
433 case 0x4B: /* LD C,E */ 469 case 0x4B: /* LD C,E */
434 DYNA_MOVE_b_r_to_r(5,3); 470#ifdef DYNA_DEBUG
471 fdprintf(fd,"LD C,E\n");
472#endif
473 DYNA_MOVE_b_r_to_r(5,3);
435 break; 474 break;
436 case 0x4C: /* LD C,H */ 475 case 0x4C: /* LD C,H */
437 GETUPPER(6,0); 476#ifdef DYNA_DEBUG
477 fdprintf(fd,"LD C,H\n");
478#endif
479 GETUPPER(6,0);
438 DYNA_MOVE_b_r_to_r(0,3); 480 DYNA_MOVE_b_r_to_r(0,3);
439 break; 481 break;
440 case 0x4D: /* LD C,L */ 482 case 0x4D: /* LD C,L */
441 DYNA_MOVE_b_r_to_r(6,3); 483#ifdef DYNA_DEBUG
484 fdprintf(fd,"LD C,L\n");
485#endif
486 DYNA_MOVE_b_r_to_r(6,3);
442 break; 487 break;
443 case 0x4F: /* LD C,A */ 488 case 0x4F: /* LD C,A */
444 DYNA_MOVE_b_r_to_r(1,3); 489#ifdef DYNA_DEBUG
490 fdprintf(fd,"LD C,A\n");
491#endif
492 DYNA_MOVE_b_r_to_r(1,3);
445 break; 493 break;
446 494
447 case 0x50: /* LD D,B */ 495 case 0x50: /* LD D,B */
448 DYNA_MOVE_b_r_to_r(2,4); 496#ifdef DYNA_DEBUG
497 fdprintf(fd,"LD D,B\n");
498#endif
499 DYNA_MOVE_b_r_to_r(2,4);
449 break; 500 break;
450 case 0x51: /* LD D,C */ 501 case 0x51: /* LD D,C */
451 DYNA_MOVE_b_r_to_r(3,4); 502#ifdef DYNA_DEBUG
503 fdprintf(fd,"LD D,C\n");
504#endif
505 DYNA_MOVE_b_r_to_r(3,4);
452 break; 506 break;
453 case 0x53: /* LD D,E */ 507 case 0x53: /* LD D,E */
454 DYNA_MOVE_b_r_to_r(5,4); 508#ifdef DYNA_DEBUG
509 fdprintf(fd,"LD B,A\n");
510#endif
511 DYNA_MOVE_b_r_to_r(5,4);
455 break; 512 break;
456 case 0x54: /* LD D,H */ 513 case 0x54: /* LD D,H */
457 GETUPPER(6,0); 514#ifdef DYNA_DEBUG
515 fdprintf(fd,"LD B,A\n");
516#endif
517 GETUPPER(6,0);
458 DYNA_MOVE_b_r_to_r(0,4); 518 DYNA_MOVE_b_r_to_r(0,4);
459 break; 519 break;
460 case 0x55: /* LD D,L */ 520 case 0x55: /* LD D,L */
461 DYNA_MOVE_b_r_to_r(6,4); 521#ifdef DYNA_DEBUG
522 fdprintf(fd,"LD B,A\n");
523#endif
524 DYNA_MOVE_b_r_to_r(6,4);
462 break; 525 break;
463 case 0x57: /* LD D,A */ 526 case 0x57: /* LD D,A */
464 DYNA_MOVE_b_r_to_r(1,4); 527#ifdef DYNA_DEBUG
528 fdprintf(fd,"LD B,A\n");
529#endif
530 DYNA_MOVE_b_r_to_r(1,4);
465 break; 531 break;
466 532
467 case 0x58: /* LD E,B */ 533 case 0x58: /* LD E,B */
468 DYNA_MOVE_b_r_to_r(2,5); 534#ifdef DYNA_DEBUG
535 fdprintf(fd,"LD E,B\n");
536#endif
537 DYNA_MOVE_b_r_to_r(2,5);
469 break; 538 break;
470 case 0x59: /* LD E,C */ 539 case 0x59: /* LD E,C */
471 DYNA_MOVE_b_r_to_r(3,5); 540#ifdef DYNA_DEBUG
541 fdprintf(fd,"LD E,C\n");
542#endif
543 DYNA_MOVE_b_r_to_r(3,5);
472 break; 544 break;
473 case 0x5A: /* LD E,D */ 545 case 0x5A: /* LD E,D */
474 DYNA_MOVE_b_r_to_r(4,5); 546#ifdef DYNA_DEBUG
547 fdprintf(fd,"LD E,D\n");
548#endif
549 DYNA_MOVE_b_r_to_r(4,5);
475 break; 550 break;
476 case 0x5C: /* LD E,H */ 551 case 0x5C: /* LD E,H */
477 GETUPPER(6,0); 552#ifdef DYNA_DEBUG
553 fdprintf(fd,"LD E,H\n");
554#endif
555 GETUPPER(6,0);
478 DYNA_MOVE_b_r_to_r(0,5); 556 DYNA_MOVE_b_r_to_r(0,5);
479 break; 557 break;
480 case 0x5D: /* LD E,L */ 558 case 0x5D: /* LD E,L */
481 DYNA_MOVE_b_r_to_r(6,5); 559#ifdef DYNA_DEBUG
560 fdprintf(fd,"LD E,L\n");
561#endif
562 DYNA_MOVE_b_r_to_r(6,5);
482 break; 563 break;
483 case 0x5F: /* LD E,A */ 564 case 0x5F: /* LD E,A */
484 DYNA_MOVE_b_r_to_r(1,5); 565#ifdef DYNA_DEBUG
566 fdprintf(fd,"LD E,A\n");
567#endif
568 DYNA_MOVE_b_r_to_r(1,5);
485 break; 569 break;
486 570
487 case 0x60: /* LD H,B */ 571 case 0x60: /* LD H,B */
488 DYNA_MOVE_b_r_to_r(2,0); 572#ifdef DYNA_DEBUG
573 fdprintf(fd,"LD H,B\n");
574#endif
575 DYNA_MOVE_b_r_to_r(2,0);
489 PUTUPPER(0,6); 576 PUTUPPER(0,6);
490 break; 577 break;
491 case 0x61: /* LD H,C */ 578 case 0x61: /* LD H,C */
492 DYNA_MOVE_b_r_to_r(3,0); 579#ifdef DYNA_DEBUG
580 fdprintf(fd,"LD H,C\n");
581#endif
582 DYNA_MOVE_b_r_to_r(3,0);
493 PUTUPPER(0,6); 583 PUTUPPER(0,6);
494 break; 584 break;
495 case 0x62: /* LD H,D */ 585 case 0x62: /* LD H,D */
496 DYNA_MOVE_b_r_to_r(4,0); 586#ifdef DYNA_DEBUG
587 fdprintf(fd,"LD H,D\n");
588#endif
589 DYNA_MOVE_b_r_to_r(4,0);
497 PUTUPPER(0,6); 590 PUTUPPER(0,6);
498 break; 591 break;
499 case 0x63: /* LD H,E */ 592 case 0x63: /* LD H,E */
500 DYNA_MOVE_b_r_to_r(5,0); 593#ifdef DYNA_DEBUG
594 fdprintf(fd,"LD H,E\n");
595#endif
596 DYNA_MOVE_b_r_to_r(5,0);
501 PUTUPPER(0,6); 597 PUTUPPER(0,6);
502 break; 598 break;
503 case 0x65: /* LD H,L */ 599 case 0x65: /* LD H,L */
504 DYNA_MOVE_b_r_to_r(6,0); 600#ifdef DYNA_DEBUG
601 fdprintf(fd,"LD H,L\n");
602#endif
603 DYNA_MOVE_b_r_to_r(6,0);
505 PUTUPPER(0,6); 604 PUTUPPER(0,6);
506 break; 605 break;
507 case 0x67: /* LD H,A */ 606 case 0x67: /* LD H,A */
607#ifdef DYNA_DEBUG
608 fdprintf(fd,"LD H,A\n");
609#endif
508 DYNA_MOVE_b_r_to_r(1,0); 610 DYNA_MOVE_b_r_to_r(1,0);
509 PUTUPPER(0,6); 611 PUTUPPER(0,6);
510 break; 612 break;
511 case 0x68: /* LD L,B */ 613 case 0x68: /* LD L,B */
512 DYNA_MOVE_b_r_to_r(2,6); 614#ifdef DYNA_DEBUG
615 fdprintf(fd,"LD L,B\n");
616#endif
617 DYNA_MOVE_b_r_to_r(2,6);
513 break; 618 break;
514 case 0x69: /* LD L,C */ 619 case 0x69: /* LD L,C */
515 DYNA_MOVE_b_r_to_r(3,6); 620#ifdef DYNA_DEBUG
621 fdprintf(fd,"LD L,C\n");
622#endif
623 DYNA_MOVE_b_r_to_r(3,6);
516 break; 624 break;
517 case 0x6A: /* LD L,D */ 625 case 0x6A: /* LD L,D */
518 DYNA_MOVE_b_r_to_r(4,6); 626#ifdef DYNA_DEBUG
627 fdprintf(fd,"LD L,D\n");
628#endif
629 DYNA_MOVE_b_r_to_r(4,6);
519 break; 630 break;
520 case 0x6B: /* LD L,E */ 631 case 0x6B: /* LD L,E */
521 DYNA_MOVE_b_r_to_r(5,6); 632#ifdef DYNA_DEBUG
633 fdprintf(fd,"LD L,E\n");
634#endif
635 DYNA_MOVE_b_r_to_r(5,6);
522 break; 636 break;
523 case 0x6C: /* LD L,H */ 637 case 0x6C: /* LD L,H */
524 GETUPPER(6,0); 638#ifdef DYNA_DEBUG
639 fdprintf(fd,"LD L,H\n");
640#endif
641 GETUPPER(6,0);
525 DYNA_MOVE_b_r_to_r(0,6); 642 DYNA_MOVE_b_r_to_r(0,6);
526 break; 643 break;
527 644
528 case 0x78: /* LD A,B */ 645 case 0x78: /* LD A,B */
529 DYNA_MOVE_b_r_to_r(2,1); 646#ifdef DYNA_DEBUG
647 fdprintf(fd,"LD A,B\n");
648#endif
649 DYNA_MOVE_b_r_to_r(2,1);
530 break; 650 break;
531 case 0x79: /* LD A,C */ 651 case 0x79: /* LD A,C */
532 DYNA_MOVE_b_r_to_r(3,1); 652#ifdef DYNA_DEBUG
653 fdprintf(fd,"LD A,C\n");
654#endif
655 DYNA_MOVE_b_r_to_r(3,1);
533 break; 656 break;
534 case 0x7A: /* LD A,D */ 657 case 0x7A: /* LD A,D */
535 DYNA_MOVE_b_r_to_r(4,1); 658#ifdef DYNA_DEBUG
659 fdprintf(fd,"LD A,D\n");
660#endif
661 DYNA_MOVE_b_r_to_r(4,1);
536 break; 662 break;
537 case 0x7B: /* LD A,E */ 663 case 0x7B: /* LD A,E */
538 DYNA_MOVE_b_r_to_r(5,1); 664#ifdef DYNA_DEBUG
665 fdprintf(fd,"LD A,E\n");
666#endif
667 DYNA_MOVE_b_r_to_r(5,1);
539 break; 668 break;
540 case 0x7C: /* LD A,H */ 669 case 0x7C: /* LD A,H */
541 GETUPPER(5,0); 670#ifdef DYNA_DEBUG
671 fdprintf(fd,"LD A,H\n");
672#endif
673 GETUPPER(5,0);
542 DYNA_MOVE_b_r_to_r(0,1); 674 DYNA_MOVE_b_r_to_r(0,1);
543 break; 675 break;
544 case 0x7D: /* LD A,L */ 676 case 0x7D: /* LD A,L */
545 DYNA_MOVE_b_r_to_r(5,1); 677#ifdef DYNA_DEBUG
678 fdprintf(fd,"LD A,L\n");
679#endif
680 DYNA_MOVE_b_r_to_r(5,1);
546 break; 681 break;
547 case 0x01: /* LD BC,imm */ 682 case 0x01: /* LD BC,imm */
548 { /* warning (do we have endianness right?) */ 683 { /* warning (do we have endianness right?) */
549 temp=readw(xPC); 684#ifdef DYNA_DEBUG
685 fdprintf(fd,"LD BC,#0x%x\n",readw(xPC));
686#endif
687 temp=readw(xPC);
550 DYNA_MOVEQ_l_i_to_r((temp&0xFF00)>>8,2); 688 DYNA_MOVEQ_l_i_to_r((temp&0xFF00)>>8,2);
551 DYNA_MOVEQ_l_i_to_r(temp&0xFF,3); 689 DYNA_MOVEQ_l_i_to_r(temp&0xFF,3);
552 PC+=2; 690 PC+=2;
553 } 691 }
554 break; 692 break;
555 case 0x11: /* LD DE,imm */ 693 case 0x11: /* LD DE,imm */
556 { temp=readw(xPC); 694 {
695#ifdef DYNA_DEBUG
696 fdprintf(fd,"LD DE,#0x%x\n",readw(xPC));
697#endif
698 temp=readw(xPC);
557 DYNA_MOVEQ_l_i_to_r((temp&0xFF00)>>8,4); 699 DYNA_MOVEQ_l_i_to_r((temp&0xFF00)>>8,4);
558 DYNA_MOVEQ_l_i_to_r(temp&0xFF,5); 700 DYNA_MOVEQ_l_i_to_r(temp&0xFF,5);
559 PC += 2; 701 PC += 2;
@@ -561,11 +703,17 @@ void dynamic_recompile (struct dynarec_block *newblock) {
561 break; 703 break;
562 case 0x21: /* LD HL,imm */ 704 case 0x21: /* LD HL,imm */
563 { 705 {
706#ifdef DYNA_DEBUG
707 fdprintf(fd,"LD HL,#0x%x\n",readw(xPC));
708#endif
564 DYNA_MOVE_l_i_to_r(readw(xPC),6); 709 DYNA_MOVE_l_i_to_r(readw(xPC),6);
565 PC += 2; 710 PC += 2;
566 } 711 }
567 break; 712 break;
568 case 0x22: /* LDI (HL), A */ 713 case 0x22: /* LDI (HL), A */
714#ifdef DYNA_DEBUG
715 fdprintf(fd,"LDI (HL),A\n");
716#endif
569 DYNA_PUSH_l_r(1,0); 717 DYNA_PUSH_l_r(1,0);
570 DYNA_PUSH_l_r(6,0); 718 DYNA_PUSH_l_r(6,0);
571 CALL_NATIVE(&writeb); 719 CALL_NATIVE(&writeb);
@@ -573,44 +721,77 @@ void dynamic_recompile (struct dynarec_block *newblock) {
573 DYNA_INC_l_r(6,0); 721 DYNA_INC_l_r(6,0);
574 break; 722 break;
575 case 0x31: /* LD SP,imm */ 723 case 0x31: /* LD SP,imm */
724#ifdef DYNA_DEBUG
725 fdprintf(fd,"LD SP,#0x%x\n",readw(xPC));
726#endif
576 DYNA_MOVEA_l_i_to_r(readw(xPC),0); 727 DYNA_MOVEA_l_i_to_r(readw(xPC),0);
577 PC += 2; 728 PC += 2;
578 break; 729 break;
579 730
580 case 0x06: /* LD B,imm */ 731 case 0x06: /* LD B,imm */
732#ifdef DYNA_DEBUG
733 fdprintf(fd,"LD B,#0x%x\n",readb(xPC));
734#endif
581 DYNA_MOVEQ_l_i_to_r(FETCH,2); 735 DYNA_MOVEQ_l_i_to_r(FETCH,2);
582 break; 736 break;
583 case 0x0E: /* LD C,imm */ 737 case 0x0E: /* LD C,imm */
584 DYNA_MOVEQ_l_i_to_r(FETCH,3); 738#ifdef DYNA_DEBUG
739 fdprintf(fd,"LD C,#0x%x\n",readb(xPC));
740#endif
741 DYNA_MOVEQ_l_i_to_r(FETCH,3);
585 break; 742 break;
586 case 0x16: /* LD D,imm */ 743 case 0x16: /* LD D,imm */
587 DYNA_MOVEQ_l_i_to_r(FETCH,4); 744#ifdef DYNA_DEBUG
745 fdprintf(fd,"LD D,#0x%x\n",readb(xPC));
746#endif
747 DYNA_MOVEQ_l_i_to_r(FETCH,4);
588 break; 748 break;
589 case 0x1E: /* LD E,imm */ 749 case 0x1E: /* LD E,imm */
590 DYNA_MOVEQ_l_i_to_r(FETCH,5); 750#ifdef DYNA_DEBUG
751 fdprintf(fd,"LD E,#0x%x\n",readb(xPC));
752#endif
753 DYNA_MOVEQ_l_i_to_r(FETCH,5);
591 break; 754 break;
592 case 0x26: /* LD H,imm */ 755 case 0x26: /* LD H,imm */
593 DYNA_AND_l_i_to_r(0xFF,6); 756#ifdef DYNA_DEBUG
757 fdprintf(fd,"LD H,#0x%x\n",readb(xPC));
758#endif
759 DYNA_AND_l_i_to_r(0xFF,6);
594 DYNA_OR_l_i_to_r(FETCH<<8,6); 760 DYNA_OR_l_i_to_r(FETCH<<8,6);
595 break; 761 break;
596 case 0x2E: /* LD L,imm */ 762 case 0x2E: /* LD L,imm */
597 DYNA_AND_l_i_to_r(0xFF00,6); 763#ifdef DYNA_DEBUG
764 fdprintf(fd,"LD L,#0x%x\n",readb(xPC));
765#endif
766 DYNA_AND_l_i_to_r(0xFF00,6);
598 DYNA_OR_l_i_to_r(FETCH,6); 767 DYNA_OR_l_i_to_r(FETCH,6);
599 break; 768 break;
600 case 0x3E: /* LD A,imm */ 769 case 0x3E: /* LD A,imm */
601 DYNA_MOVEQ_l_i_to_r(FETCH,1); 770#ifdef DYNA_DEBUG
771 fdprintf(fd,"LD A,#0x%x\n",readb(xPC));
772#endif
773 DYNA_MOVEQ_l_i_to_r(FETCH,1);
602 break; 774 break;
603 775
604 case 0xF9: /* LD SP,HL */ 776 case 0xF9: /* LD SP,HL */
605 DYNA_MOVEA_w_r_to_r(6,0,0); 777#ifdef DYNA_DEBUG
778 fdprintf(fd,"LD SP,HL\n");
779#endif
780 DYNA_MOVEA_w_r_to_r(6,0,0);
606 break; 781 break;
607 case 0xF3: /* DI */ 782 case 0xF3: /* DI */
783#ifdef DYNA_DEBUG
784 fdprintf(fd,"DI\n");
785#endif
608 DYNA_CLR_l_m(&cpu.ime); 786 DYNA_CLR_l_m(&cpu.ime);
609 DYNA_CLR_l_m(&cpu.ima); 787 DYNA_CLR_l_m(&cpu.ima);
610 DYNA_CLR_l_m(&cpu.halt); 788 DYNA_CLR_l_m(&cpu.halt);
611 /* cpu.halt = cpu.ima = cpu.ime = 0; */ 789 /* cpu.halt = cpu.ima = cpu.ime = 0; */
612 break; 790 break;
613 case 0xFB: /* EI */ 791 case 0xFB: /* EI */
792#ifdef DYNA_DEBUG
793 fdprintf(fd,"EI\n");
794#endif
614 DYNA_MOVEQ_l_i_to_r(1,0); 795 DYNA_MOVEQ_l_i_to_r(1,0);
615 DYNA_MOVEA_l_i_to_r(&cpu.ima,3); 796 DYNA_MOVEA_l_i_to_r(&cpu.ima,3);
616 DYNA_MOVE_l_r_to_m(0,3); 797 DYNA_MOVE_l_r_to_m(0,3);
@@ -618,7 +799,10 @@ void dynamic_recompile (struct dynarec_block *newblock) {
618 break; 799 break;
619 800
620 case 0xE0: /* LDH (imm),A */ 801 case 0xE0: /* LDH (imm),A */
621 DYNA_PUSH_l_r(1,0); 802#ifdef DYNA_DEBUG
803 fdprintf(fd,"LD (0x%x),A\n",readb(xPC));
804#endif
805 DYNA_PUSH_l_r(1,0);
622 DYNA_PEA_w_i(FETCH); 806 DYNA_PEA_w_i(FETCH);
623 CALL_NATIVE(&writehi); 807 CALL_NATIVE(&writehi);
624 DYNA_ADDQ_l_i_to_r(0,7,1); 808 DYNA_ADDQ_l_i_to_r(0,7,1);
@@ -626,20 +810,32 @@ void dynamic_recompile (struct dynarec_block *newblock) {
626 break; 810 break;
627 811
628 case 0xC3: /* JP (imm) PC = readw(PC) */ 812 case 0xC3: /* JP (imm) PC = readw(PC) */
813#ifdef DYNA_DEBUG
814 fdprintf(fd,"JP (0x%x)\n",readw(xPC));
815#endif
629 PC=readw(PC); 816 PC=readw(PC);
630 done=1; 817 done=1;
631 break; 818 break;
632 case 0xCD: /* CALL (imm) PUSH(PC+2) PC=readw(PC); */ 819 case 0xCD: /* CALL (imm) PUSH(PC+2) PC=readw(PC); */
820#ifdef DYNA_DEBUG
821 fdprintf(fd,"CALL (0x%x)\n",readw(xPC));
822#endif
633 PUSH(PC+2); 823 PUSH(PC+2);
634 PC=readw(PC); 824 PC=readw(PC);
635 done=1; 825 done=1;
636 break; 826 break;
637 827
638 case 0x97: /* SUB A (halfcarry ?) */ 828 case 0x97: /* SUB A (halfcarry ?) */
829#ifdef DYNA_DEBUG
830 fdprintf(fd,"SUB A\n");
831#endif
639 DYNA_CLR_l_r(1); 832 DYNA_CLR_l_r(1);
640 DYNA_MOVEQ_l_i_to_r(0xC0,7); 833 DYNA_MOVEQ_l_i_to_r(0xC0,7);
641 break; 834 break;
642 case 0xF0: 835 case 0xF0: /* LDH A,(imm) */
836#ifdef DYNA_DEBUG
837 fdprintf(fd,"LDH A,(0x%x)\n",readb(xPC));
838#endif
643 DYNA_PEA_w_i(FETCH); 839 DYNA_PEA_w_i(FETCH);
644 CALL_NATIVE(&readhi); 840 CALL_NATIVE(&readhi);
645 DYNA_ADDQ_l_i_to_r(4,7,1); 841 DYNA_ADDQ_l_i_to_r(4,7,1);
@@ -647,6 +843,9 @@ void dynamic_recompile (struct dynarec_block *newblock) {
647 /*A = readhi(FETCH)*/ 843 /*A = readhi(FETCH)*/
648 break; 844 break;
649 case 0x87: // ADD A,A 845 case 0x87: // ADD A,A
846#ifdef DYNA_DEBUG
847 fdprintf(fd,"ADD A,A\n");
848#endif
650 /* code taken from gcc -O3 output by compiling; 849 /* code taken from gcc -O3 output by compiling;
651 * c=(2*b)&0xFF; 850 * c=(2*b)&0xFF;
652 * a=(c) ? 0 : 0x80 | // zero flag 851 * a=(c) ? 0 : 0x80 | // zero flag
@@ -672,6 +871,9 @@ void dynamic_recompile (struct dynarec_block *newblock) {
672 DYNA_AND_l_i_to_r(0xB0,7); /* and.l #0xB0,d7 */ 871 DYNA_AND_l_i_to_r(0xB0,7); /* and.l #0xB0,d7 */
673 break; 872 break;
674 case 0xD0: /* RET NC */ 873 case 0xD0: /* RET NC */
874#ifdef DYNA_DEBUG
875 fdprintf(fd,"RET NC\n");
876#endif
675 DYNA_BTST_l_r(5,7); /* btst #5,d7 */ 877 DYNA_BTST_l_r(5,7); /* btst #5,d7 */
676 DYNA_DUMMYBRANCH(2,0); 878 DYNA_DUMMYBRANCH(2,0);
677 POPA(1); /* POP %a1 */ 879 POPA(1); /* POP %a1 */
@@ -682,11 +884,17 @@ void dynamic_recompile (struct dynarec_block *newblock) {
682 tclen-=3; 884 tclen-=3;
683 break; 885 break;
684 case 0xC9: /* RET */ 886 case 0xC9: /* RET */
887#ifdef DYNA_DEBUG
888 fdprintf(fd,"RET\n");
889#endif
685 POPA(1); 890 POPA(1);
686 writepc=0; 891 writepc=0;
687 done=1; 892 done=1;
688 break; 893 break;
689 case 0x20: /* JR NZ */ 894 case 0x20: /* JR NZ */
895#ifdef DYNA_DEBUG
896 fdprintf(fd,"JR NZ\n");
897#endif
690 DYNA_BTST_l_r(8,7); /* btst #8,d7 */ 898 DYNA_BTST_l_r(8,7); /* btst #8,d7 */
691 DYNA_DUMMYBRANCH(2,0); 899 DYNA_DUMMYBRANCH(2,0);
692 DYNA_MOVEA_l_i_to_r(&blockclen,3); 900 DYNA_MOVEA_l_i_to_r(&blockclen,3);
@@ -698,6 +906,9 @@ void dynamic_recompile (struct dynarec_block *newblock) {
698 PC++; 906 PC++;
699 break; 907 break;
700 case 0xC2: /* JP NZ */ 908 case 0xC2: /* JP NZ */
909#ifdef DYNA_DEBUG
910 fdprintf(fd,"JP NZ\n");
911#endif
701 DYNA_BTST_l_r(8,7); /* btst #8,d7 */ 912 DYNA_BTST_l_r(8,7); /* btst #8,d7 */
702 DYNA_DUMMYBRANCH(2,0); 913 DYNA_DUMMYBRANCH(2,0);
703 DYNA_MOVEA_l_i_to_r(&blockclen,3); 914 DYNA_MOVEA_l_i_to_r(&blockclen,3);
@@ -708,6 +919,9 @@ void dynamic_recompile (struct dynarec_block *newblock) {
708 PC+=2; 919 PC+=2;
709 break; 920 break;
710/* case 0xFA: /* LD A, (imm) 921/* case 0xFA: /* LD A, (imm)
922#ifdef DYNA_DEBUG
923 fdprintf(fd,"LD A,(0x%x)\n",readw(xPC));
924#endif
711 DYNA_PEA_w_i(readw(xPC)); 925 DYNA_PEA_w_i(readw(xPC));
712 PC+=2; \ 926 PC+=2; \
713 CALL_NATIVE(&readb); \ 927 CALL_NATIVE(&readb); \
@@ -716,13 +930,19 @@ void dynamic_recompile (struct dynarec_block *newblock) {
716 break; */ 930 break; */
717 931
718 case 0xFE: /* CMP #<imm> TODO: can be (much) more efficient.*/ 932 case 0xFE: /* CMP #<imm> TODO: can be (much) more efficient.*/
719 DYNA_MOVEA_l_r_to_r(2,3,0); /* movea.l %d2, %a3 */ 933#ifdef DYNA_DEBUG
934 fdprintf(fd,"CMP #0x%x\n",readb(xPC));
935#endif
936 DYNA_MOVEA_l_r_to_r(2,3,0); /* movea.l %d2, %a3 */
720 DYNA_MOVEQ_l_i_to_r(FETCH,2); /* moveq.l #<FETCH>,%d2 */ 937 DYNA_MOVEQ_l_i_to_r(FETCH,2); /* moveq.l #<FETCH>,%d2 */
721 CMP(2); 938 CMP(2);
722 DYNA_MOVE_l_r_to_r(3,2,1); /* move.l %a3, %d2 */ 939 DYNA_MOVE_l_r_to_r(3,2,1); /* move.l %a3, %d2 */
723 break; 940 break;
724 941
725 case 0xB1: /* OR C */ 942 case 0xB1: /* OR C */
943#ifdef DYNA_DEBUG
944 fdprintf(fd,"OR C\n");
945#endif
726 DYNA_OR_l_r_to_r(3,1); // or %d3,%d1 946 DYNA_OR_l_r_to_r(3,1); // or %d3,%d1
727 DYNA_MOVEQ_l_i_to_r(0,7); 947 DYNA_MOVEQ_l_i_to_r(0,7);
728 DYNA_TST_b_r(1,0); 948 DYNA_TST_b_r(1,0);
@@ -737,6 +957,10 @@ void dynamic_recompile (struct dynarec_block *newblock) {
737 break; 957 break;
738 } 958 }
739 } 959 }
960#ifdef DYNA_DEBUG
961 fdprintf(fd,"(End of Block)\n");
962 close(fd);
963#endif
740 DYNA_MOVEA_l_i_to_r(&blockclen,3); 964 DYNA_MOVEA_l_i_to_r(&blockclen,3);
741 DYNA_MOVE_l_i_to_m(tclen,3); 965 DYNA_MOVE_l_i_to_m(tclen,3);
742 if(writepc) 966 if(writepc)
@@ -746,5 +970,11 @@ void dynamic_recompile (struct dynarec_block *newblock) {
746 setmallocpos(dynapointer); 970 setmallocpos(dynapointer);
747 newblock->length=dynapointer-newblock->block; 971 newblock->length=dynapointer-newblock->block;
748 invalidate_icache(); 972 invalidate_icache();
973 snprintf(meow,499,"/dyna_0x%x_code.rb",PC);
974 fd=open(meow,O_WRONLY|O_CREAT);
975 if(fd>=0) {
976 write(fd,newblock->block,newblock->length);
977 close(fd);
978 }
749} 979}
750#endif 980#endif