ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/uae_cpu/gencpu.c
(Generate patch)

Comparing BasiliskII/src/uae_cpu/gencpu.c (file contents):
Revision 1.13 by gbeauche, 2001-03-20T17:35:46Z vs.
Revision 1.26 by asvitkine, 2012-03-30T01:25:46Z

# Line 14 | Line 14
14   * take care of this.
15   *
16   * Copyright 1995, 1996 Bernd Schmidt
17 + *
18 + * This program is free software; you can redistribute it and/or modify
19 + * it under the terms of the GNU General Public License as published by
20 + * the Free Software Foundation; either version 2 of the License, or
21 + * (at your option) any later version.
22 + *
23 + * This program is distributed in the hope that it will be useful,
24 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26 + * GNU General Public License for more details.
27 + *
28 + * You should have received a copy of the GNU General Public License
29 + * along with this program; if not, write to the Free Software
30 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
31 + *
32   */
33  
34   #include <ctype.h>
# Line 30 | Line 45
45  
46   #define BOOL_TYPE "int"
47  
48 + /* Define the minimal 680x0 where NV flags are not affected by xBCD instructions.  */
49 + #define xBCD_KEEPS_NV_FLAGS 4
50 +
51   static FILE *headerfile;
52   static FILE *stblfile;
53  
# Line 568 | Line 586 | static void duplicate_carry (void)
586   }
587  
588   typedef enum {
589 <    flag_logical_noclobber, flag_logical, flag_add, flag_sub, flag_cmp, flag_addx, flag_subx, flag_zn,
589 >    flag_logical_noclobber, flag_logical, flag_add, flag_sub, flag_cmp, flag_addx, flag_subx, flag_z, flag_zn,
590      flag_av, flag_sv
591   } flagtypes;
592  
# Line 622 | Line 640 | static void genflags_normal (flagtypes t
640      switch (type) {
641       case flag_logical_noclobber:
642       case flag_logical:
643 +     case flag_z:
644       case flag_zn:
645       case flag_av:
646       case flag_sv:
# Line 643 | Line 662 | static void genflags_normal (flagtypes t
662      switch (type) {
663       case flag_logical_noclobber:
664       case flag_logical:
665 +     case flag_z:
666       case flag_zn:
667          break;
668  
# Line 676 | Line 696 | static void genflags_normal (flagtypes t
696       case flag_sv:
697          printf ("\tSET_VFLG ((flgs ^ flgo) & (flgn ^ flgo));\n");
698          break;
699 +     case flag_z:
700 +        printf ("\tSET_ZFLG (GET_ZFLG & (%s == 0));\n", vstr);
701 +        break;
702       case flag_zn:
703          printf ("\tSET_ZFLG (GET_ZFLG & (%s == 0));\n", vstr);
704          printf ("\tSET_NFLG (%s < 0);\n", vstr);
# Line 715 | Line 738 | static void genflags_normal (flagtypes t
738  
739   static void genflags (flagtypes type, wordsizes size, char *value, char *src, char *dst)
740   {
741 < #ifdef SPARC_V8_ASSEMBLY
742 <        switch(type)
743 <        {
744 <                case flag_add:
722 <                        start_brace();
723 <                        printf("\tuae_u32 %s;\n", value);
724 <                        switch(size)
725 <                        {
726 <                                case sz_byte:
727 <                                        printf("\t%s = sparc_v8_flag_add_8(&regflags, (uae_u32)(%s), (uae_u32)(%s));\n", value, src, dst);
728 <                                        break;
729 <                                case sz_word:
730 <                                        printf("\t%s = sparc_v8_flag_add_16(&regflags, (uae_u32)(%s), (uae_u32)(%s));\n", value, src, dst);
731 <                                        break;
732 <                                case sz_long:
733 <                                        printf("\t%s = sparc_v8_flag_add_32(&regflags, (uae_u32)(%s), (uae_u32)(%s));\n", value, src, dst);
734 <                                        break;
735 <                        }
736 <                        return;
737 <                
738 <                case flag_sub:
739 <                        start_brace();
740 <                        printf("\tuae_u32 %s;\n", value);
741 <                        switch(size)
742 <                        {
743 <                                case sz_byte:
744 <                                        printf("\t%s = sparc_v8_flag_sub_8(&regflags, (uae_u32)(%s), (uae_u32)(%s));\n", value, src, dst);
745 <                                        break;
746 <                                case sz_word:
747 <                                        printf("\t%s = sparc_v8_flag_sub_16(&regflags, (uae_u32)(%s), (uae_u32)(%s));\n", value, src, dst);
748 <                                        break;
749 <                                case sz_long:
750 <                                        printf("\t%s = sparc_v8_flag_sub_32(&regflags, (uae_u32)(%s), (uae_u32)(%s));\n", value, src, dst);
751 <                                        break;
752 <                        }
753 <                        return;
754 <                
755 <                case flag_cmp:
756 <                        switch(size)
757 <                        {
758 <                                case sz_byte:
759 < //                                      printf("\tsparc_v8_flag_cmp_8(&regflags, (uae_u32)(%s), (uae_u32)(%s));\n", src, dst);
760 <                                        break;
761 <                                case sz_word:
762 < //                                      printf("\tsparc_v8_flag_cmp_16(&regflags, (uae_u32)(%s), (uae_u32)(%s));\n", src, dst);
763 <                                        break;
764 <                                case sz_long:
765 < #if 1
766 <                                        printf("\tsparc_v8_flag_cmp_32(&regflags, (uae_u32)(%s), (uae_u32)(%s));\n", src, dst);
767 <                                        return;
768 < #endif
769 <                                        break;
770 <                        }
771 < //                      return;
772 <                        break;
773 <        }
774 < #elif defined(SPARC_V9_ASSEMBLY)
775 <        switch(type)
776 <        {
777 <                case flag_add:
778 <                        start_brace();
779 <                        printf("\tuae_u32 %s;\n", value);
780 <                        switch(size)
781 <                        {
782 <                                case sz_byte:
783 <                                        printf("\t%s = sparc_v9_flag_add_8(&regflags, (uae_u32)(%s), (uae_u32)(%s));\n", value, src, dst);
784 <                                        break;
785 <                                case sz_word:
786 <                                        printf("\t%s = sparc_v9_flag_add_16(&regflags, (uae_u32)(%s), (uae_u32)(%s));\n", value, src, dst);
787 <                                        break;
788 <                                case sz_long:
789 <                                        printf("\t%s = sparc_v9_flag_add_32(&regflags, (uae_u32)(%s), (uae_u32)(%s));\n", value, src, dst);
790 <                                        break;
791 <                        }
792 <                        return;
793 <                
794 <                case flag_sub:
795 <                        start_brace();
796 <                        printf("\tuae_u32 %s;\n", value);
797 <                        switch(size)
798 <                        {
799 <                                case sz_byte:
800 <                                        printf("\t%s = sparc_v9_flag_sub_8(&regflags, (uae_u32)(%s), (uae_u32)(%s));\n", value, src, dst);
801 <                                        break;
802 <                                case sz_word:
803 <                                        printf("\t%s = sparc_v9_flag_sub_16(&regflags, (uae_u32)(%s), (uae_u32)(%s));\n", value, src, dst);
804 <                                        break;
805 <                                case sz_long:
806 <                                        printf("\t%s = sparc_v9_flag_sub_32(&regflags, (uae_u32)(%s), (uae_u32)(%s));\n", value, src, dst);
807 <                                        break;
808 <                        }
809 <                        return;
810 <                
811 <                case flag_cmp:
812 <                        switch(size)
813 <                        {
814 <                                case sz_byte:
815 <                                        printf("\tsparc_v9_flag_cmp_8(&regflags, (uae_u32)(%s), (uae_u32)(%s));\n", src, dst);
816 <                                        break;
817 <                                case sz_word:
818 <                                        printf("\tsparc_v9_flag_cmp_16(&regflags, (uae_u32)(%s), (uae_u32)(%s));\n", src, dst);
819 <                                        break;
820 <                                case sz_long:
821 <                                        printf("\tsparc_v9_flag_cmp_32(&regflags, (uae_u32)(%s), (uae_u32)(%s));\n", src, dst);
822 <                                        break;
823 <                        }
824 <                        return;
825 <                
826 <                case flag_logical:
827 <                        if (strcmp(value, "0") == 0) {
828 <                                printf("\tregflags.nzvc = 0x04;\n");
829 <                        } else {
830 <                                switch(size) {
831 <                                        case sz_byte:
832 <                                                printf("\tsparc_v9_flag_test_8(&regflags, (uae_u32)(%s));\n", value);
833 <                                                break;
834 <                                        case sz_word:
835 <                                                printf("\tsparc_v9_flag_test_16(&regflags, (uae_u32)(%s));\n", value);
836 <                                                break;
837 <                                        case sz_long:
838 <                                                printf("\tsparc_v9_flag_test_32(&regflags, (uae_u32)(%s));\n", value);
839 <                                                break;
840 <                                }
841 <                        }
842 <                        return;
843 <                
844 < #if 0
845 <                case flag_logical_noclobber:
846 <                        printf("\t{uae_u32 old_flags = regflags.nzvc & ~0x0C;\n");
847 <                        if (strcmp(value, "0") == 0) {
848 <                                printf("\tregflags.nzvc = old_flags | 0x04;\n");
849 <                        } else {
850 <                                switch(size) {
851 <                                        case sz_byte:
852 <                                                printf("\tsparc_v9_flag_test_8(&regflags, (uae_u32)(%s));\n", value);
853 <                                                break;
854 <                                        case sz_word:
855 <                                                printf("\tsparc_v9_flag_test_16(&regflags, (uae_u32)(%s));\n", value);
856 <                                                break;
857 <                                        case sz_long:
858 <                                                printf("\tsparc_v9_flag_test_32(&regflags, (uae_u32)(%s));\n", value);
859 <                                                break;
860 <                                }
861 <                                printf("\tregflags.nzvc |= old_flags;\n");
862 <                        }
863 <                        printf("\t}\n");
864 <                        return;
865 < #endif
866 <        }
867 < #elif defined(X86_ASSEMBLY)
741 >    /* Temporarily deleted 68k/ARM flag optimizations.  I'd prefer to have
742 >       them in the appropriate m68k.h files and use just one copy of this
743 >       code here.  The API can be changed if necessary.  */
744 > #ifdef OPTIMIZED_FLAGS
745      switch (type) {
746       case flag_add:
747       case flag_sub:
748          start_brace ();
749          printf ("\tuae_u32 %s;\n", value);
750          break;
874
751       default:
752          break;
753      }
# Line 879 | Line 755 | static void genflags (flagtypes type, wo
755      /* At least some of those casts are fairly important! */
756      switch (type) {
757       case flag_logical_noclobber:
758 <        printf ("\t{uae_u32 oldcznv = regflags.cznv & ~0xC0;\n");
758 >        printf ("\t{uae_u32 oldcznv = GET_CZNV & ~(FLAGVAL_Z | FLAGVAL_N);\n");
759          if (strcmp (value, "0") == 0) {
760 <            printf ("\tregflags.cznv = olcznv | 64;\n");
760 >            printf ("\tSET_CZNV (olcznv | FLAGVAL_Z);\n");
761          } else {
762              switch (size) {
763 <             case sz_byte: printf ("\tx86_flag_testb ((uae_s8)(%s));\n", value); break;
764 <             case sz_word: printf ("\tx86_flag_testw ((uae_s16)(%s));\n", value); break;
765 <             case sz_long: printf ("\tx86_flag_testl ((uae_s32)(%s));\n", value); break;
763 >             case sz_byte: printf ("\toptflag_testb ((uae_s8)(%s));\n", value); break;
764 >             case sz_word: printf ("\toptflag_testw ((uae_s16)(%s));\n", value); break;
765 >             case sz_long: printf ("\toptflag_testl ((uae_s32)(%s));\n", value); break;
766              }
767 <            printf ("\tregflags.cznv |= oldcznv;\n");
767 >            printf ("\tIOR_CZNV (oldcznv);\n");
768          }
769          printf ("\t}\n");
770          return;
771 +        
772       case flag_logical:
773          if (strcmp (value, "0") == 0) {
774 <            printf ("\tregflags.cznv = 64;\n");
774 >            printf ("\tSET_CZNV (FLAGVAL_Z);\n");
775          } else {
776              switch (size) {
777 <             case sz_byte: printf ("\tx86_flag_testb ((uae_s8)(%s));\n", value); break;
778 <             case sz_word: printf ("\tx86_flag_testw ((uae_s16)(%s));\n", value); break;
779 <             case sz_long: printf ("\tx86_flag_testl ((uae_s32)(%s));\n", value); break;
777 >             case sz_byte: printf ("\toptflag_testb ((uae_s8)(%s));\n", value); break;
778 >             case sz_word: printf ("\toptflag_testw ((uae_s16)(%s));\n", value); break;
779 >             case sz_long: printf ("\toptflag_testl ((uae_s32)(%s));\n", value); break;
780              }
781          }
782          return;
783  
784       case flag_add:
785          switch (size) {
786 <         case sz_byte: printf ("\tx86_flag_addb (%s, (uae_s8)(%s), (uae_s8)(%s));\n", value, src, dst); break;
787 <         case sz_word: printf ("\tx86_flag_addw (%s, (uae_s16)(%s), (uae_s16)(%s));\n", value, src, dst); break;
788 <         case sz_long: printf ("\tx86_flag_addl (%s, (uae_s32)(%s), (uae_s32)(%s));\n", value, src, dst); break;
786 >         case sz_byte: printf ("\toptflag_addb (%s, (uae_s8)(%s), (uae_s8)(%s));\n", value, src, dst); break;
787 >         case sz_word: printf ("\toptflag_addw (%s, (uae_s16)(%s), (uae_s16)(%s));\n", value, src, dst); break;
788 >         case sz_long: printf ("\toptflag_addl (%s, (uae_s32)(%s), (uae_s32)(%s));\n", value, src, dst); break;
789          }
790          return;
791  
792       case flag_sub:
793          switch (size) {
794 <         case sz_byte: printf ("\tx86_flag_subb (%s, (uae_s8)(%s), (uae_s8)(%s));\n", value, src, dst); break;
795 <         case sz_word: printf ("\tx86_flag_subw (%s, (uae_s16)(%s), (uae_s16)(%s));\n", value, src, dst); break;
796 <         case sz_long: printf ("\tx86_flag_subl (%s, (uae_s32)(%s), (uae_s32)(%s));\n", value, src, dst); break;
794 >         case sz_byte: printf ("\toptflag_subb (%s, (uae_s8)(%s), (uae_s8)(%s));\n", value, src, dst); break;
795 >         case sz_word: printf ("\toptflag_subw (%s, (uae_s16)(%s), (uae_s16)(%s));\n", value, src, dst); break;
796 >         case sz_long: printf ("\toptflag_subl (%s, (uae_s32)(%s), (uae_s32)(%s));\n", value, src, dst); break;
797          }
798          return;
799  
800       case flag_cmp:
801          switch (size) {
802 <         case sz_byte: printf ("\tx86_flag_cmpb ((uae_s8)(%s), (uae_s8)(%s));\n", src, dst); break;
803 <         case sz_word: printf ("\tx86_flag_cmpw ((uae_s16)(%s), (uae_s16)(%s));\n", src, dst); break;
804 <         case sz_long: printf ("\tx86_flag_cmpl ((uae_s32)(%s), (uae_s32)(%s));\n", src, dst); break;
802 >         case sz_byte: printf ("\toptflag_cmpb ((uae_s8)(%s), (uae_s8)(%s));\n", src, dst); break;
803 >         case sz_word: printf ("\toptflag_cmpw ((uae_s16)(%s), (uae_s16)(%s));\n", src, dst); break;
804 >         case sz_long: printf ("\toptflag_cmpl ((uae_s32)(%s), (uae_s32)(%s));\n", src, dst); break;
805          }
806          return;
807          
808       default:
809          break;
810      }
934 #elif defined(M68K_FLAG_OPT)
935    /* sam: here I'm cloning what X86_ASSEMBLY does */
936 #define EXT(size)  (size==sz_byte?"b":(size==sz_word?"w":"l"))
937 #define CAST(size) (size==sz_byte?"uae_s8":(size==sz_word?"uae_s16":"uae_s32"))
938    switch (type) {
939     case flag_add:
940     case flag_sub:
941        start_brace ();
942        printf ("\tuae_u32 %s;\n", value);
943        break;
944
945     default:
946        break;
947    }
948
949    switch (type) {
950     case flag_logical:
951        if (strcmp (value, "0") == 0) {
952            printf ("\t*(uae_u16 *)&regflags = 4;\n");  /* Z = 1 */
953        } else {
954            printf ("\tm68k_flag_tst (%s, (%s)(%s));\n",
955                    EXT (size), CAST (size), value);
956        }
957        return;
958
959     case flag_add:
960        printf ("\t{uae_u16 ccr;\n");
961        printf ("\tm68k_flag_add (%s, (%s)%s, (%s)(%s), (%s)(%s));\n",
962                EXT (size), CAST (size), value, CAST (size), src, CAST (size), dst);
963        printf ("\t((uae_u16*)&regflags)[1]=((uae_u16*)&regflags)[0]=ccr;}\n");
964        return;
965
966     case flag_sub:
967        printf ("\t{uae_u16 ccr;\n");
968        printf ("\tm68k_flag_sub (%s, (%s)%s, (%s)(%s), (%s)(%s));\n",
969                EXT (size), CAST (size), value, CAST (size), src, CAST (size), dst);
970        printf ("\t((uae_u16*)&regflags)[1]=((uae_u16*)&regflags)[0]=ccr;}\n");
971        return;
972
973     case flag_cmp:
974        printf ("\tm68k_flag_cmp (%s, (%s)(%s), (%s)(%s));\n",
975                EXT (size), CAST (size), src, CAST (size), dst);
976        return;
977
978     default:
979        break;
980    }
981 #elif defined(ACORN_FLAG_OPT) && defined(__GNUC_MINOR__)
982 /*
983 * This is new. Might be quite buggy.
984 */
985    switch (type) {
986     case flag_av:
987     case flag_sv:
988     case flag_zn:
989     case flag_addx:
990     case flag_subx:
991        break;
992
993     case flag_logical:
994        if (strcmp (value, "0") == 0) {
995            /* v=c=n=0 z=1 */
996            printf ("\t*(ULONG*)&regflags = 0x40000000;\n");
997            return;
998        } else {
999            start_brace ();
1000            switch (size) {
1001             case sz_byte:
1002                printf ("\tUBYTE ccr;\n");
1003                printf ("\tULONG shift;\n");
1004                printf ("\t__asm__(\"mov %%2,%%1,lsl#24\n\ttst %%2,%%2\n\tmov %%0,r15,lsr#24\n\tbic %%0,%%0,#0x30\"\n"
1005                        "\t: \"=r\" (ccr) : \"r\" (%s), \"r\" (shift) : \"cc\" );\n", value);
1006                printf ("\t*((UBYTE*)&regflags+3) = ccr;\n");
1007                return;
1008             case sz_word:
1009                printf ("\tUBYTE ccr;\n");
1010                printf ("\tULONG shift;\n");
1011                printf ("\t__asm__(\"mov %%2,%%1,lsl#16\n\ttst %%2,%%2\n\tmov %%0,r15,lsr#24\n\tbic %%0,%%0,#0x30\"\n"
1012                        "\t: \"=r\" (ccr) : \"r\" ((WORD)%s), \"r\" (shift) : \"cc\" );\n", value);
1013                printf ("\t*((UBYTE*)&regflags+3) = ccr;\n");
1014                return;
1015             case sz_long:
1016                printf ("\tUBYTE ccr;\n");
1017                printf ("\t__asm__(\"tst %%1,%%1\n\tmov %%0,r15,lsr#24\n\tbic %%0,%%0,#0x30\"\n"
1018                        "\t: \"=r\" (ccr) : \"r\" ((LONG)%s) : \"cc\" );\n", value);
1019                printf ("\t*((UBYTE*)&regflags+3) = ccr;\n");
1020                return;
1021            }
1022        }
1023        break;
1024     case flag_add:
1025        if (strcmp (dst, "0") == 0) {
1026            printf ("/* Error! Hier muss Peter noch was machen !!! (ADD-Flags) */");
1027        } else {
1028            start_brace ();
1029            switch (size) {
1030             case sz_byte:
1031                printf ("\tULONG ccr, shift, %s;\n", value);
1032                printf ("\t__asm__(\"mov %%4,%%3,lsl#24\n\tadds %%0,%%4,%%2,lsl#24\n\tmov %%0,%%0,asr#24\n\tmov %%1,r15\n\torr %%1,%%1,%%1,lsr#29\"\n"
1033                        "\t: \"=r\" (%s), \"=r\" (ccr) : \"r\" (%s), \"r\" (%s), \"r\" (shift) : \"cc\" );\n", value, src, dst);
1034                printf ("\t*(ULONG*)&regflags = ccr;\n");
1035                return;
1036             case sz_word:
1037                printf ("\tULONG ccr, shift, %s;\n", value);
1038                printf ("\t__asm__(\"mov %%4,%%3,lsl#16\n\tadds %%0,%%4,%%2,lsl#16\n\tmov %%0,%%0,asr#16\n\tmov %%1,r15\n\torr %%1,%%1,%%1,lsr#29\"\n"
1039                        "\t: \"=r\" (%s), \"=r\" (ccr) : \"r\" ((WORD)%s), \"r\" ((WORD)%s), \"r\" (shift) : \"cc\" );\n", value, src, dst);
1040                printf ("\t*(ULONG*)&regflags = ccr;\n");
1041                return;
1042             case sz_long:
1043                printf ("\tULONG ccr, %s;\n", value);
1044                printf ("\t__asm__(\"adds %%0,%%3,%%2\n\tmov %%1,r15\n\torr %%1,%%1,%%1,lsr#29\"\n"
1045                        "\t: \"=r\" (%s), \"=r\" (ccr) : \"r\" ((LONG)%s), \"r\" ((LONG)%s) : \"cc\" );\n", value, src, dst);
1046                printf ("\t*(ULONG*)&regflags = ccr;\n");
1047                return;
1048            }
1049        }
1050        break;
1051     case flag_sub:
1052        if (strcmp (dst, "0") == 0) {
1053            printf ("/* Error! Hier muss Peter noch was machen !!! (SUB-Flags) */");
1054        } else {
1055            start_brace ();
1056            switch (size) {
1057             case sz_byte:
1058                printf ("\tULONG ccr, shift, %s;\n", value);
1059                printf ("\t__asm__(\"mov %%4,%%3,lsl#24\n\tsubs %%0,%%4,%%2,lsl#24\n\tmov %%0,%%0,asr#24\n\tmov %%1,r15\n\teor %%1,%%1,#0x20000000\n\torr %%1,%%1,%%1,lsr#29\"\n"
1060                        "\t: \"=r\" (%s), \"=r\" (ccr) : \"r\" (%s), \"r\" (%s), \"r\" (shift) : \"cc\" );\n", value, src, dst);
1061                printf ("\t*(ULONG*)&regflags = ccr;\n");
1062                return;
1063             case sz_word:
1064                printf ("\tULONG ccr, shift, %s;\n", value);
1065                printf ("\t__asm__(\"mov %%4,%%3,lsl#16\n\tsubs %%0,%%4,%%2,lsl#16\n\tmov %%0,%%0,asr#16\n\tmov %%1,r15\n\teor %%1,%%1,#0x20000000\n\torr %%1,%%1,%%1,lsr#29\"\n"
1066                        "\t: \"=r\" (%s), \"=r\" (ccr) : \"r\" ((WORD)%s), \"r\" ((WORD)%s), \"r\" (shift) : \"cc\" );\n", value, src, dst);
1067                printf ("\t*(ULONG*)&regflags = ccr;\n");
1068                return;
1069             case sz_long:
1070                printf ("\tULONG ccr, %s;\n", value);
1071                printf ("\t__asm__(\"subs %%0,%%3,%%2\n\tmov %%1,r15\n\teor %%1,%%1,#0x20000000\n\torr %%1,%%1,%%1,lsr#29\"\n"
1072                        "\t: \"=r\" (%s), \"=r\" (ccr) : \"r\" ((LONG)%s), \"r\" ((LONG)%s) : \"cc\" );\n", value, src, dst);
1073                printf ("\t*(ULONG*)&regflags = ccr;\n");
1074                return;
1075            }
1076        }
1077        break;
1078     case flag_cmp:
1079        if (strcmp (dst, "0") == 0) {
1080            printf ("/*Error! Hier muss Peter noch was machen !!! (CMP-Flags)*/");
1081        } else {
1082            start_brace ();
1083            switch (size) {
1084             case sz_byte:
1085                printf ("\tULONG shift, ccr;\n");
1086                printf ("\t__asm__(\"mov %%3,%%2,lsl#24\n\tcmp %%3,%%1,lsl#24\n\tmov %%0,r15,lsr#24\n\teor %%0,%%0,#0x20\"\n"
1087                        "\t: \"=r\" (ccr) : \"r\" (%s), \"r\" (%s), \"r\" (shift) : \"cc\" );\n", src, dst);
1088                printf ("\t*((UBYTE*)&regflags+3) = ccr;\n");
1089                return;
1090             case sz_word:
1091                printf ("\tULONG shift, ccr;\n");
1092                printf ("\t__asm__(\"mov %%3,%%2,lsl#16\n\tcmp %%3,%%1,lsl#16\n\tmov %%0,r15,lsr#24\n\teor %%0,%%0,#0x20\"\n"
1093                        "\t: \"=r\" (ccr) : \"r\" ((WORD)%s), \"r\" ((WORD)%s), \"r\" (shift) : \"cc\" );\n", src, dst);
1094                printf ("\t*((UBYTE*)&regflags+3) = ccr;\n");
1095                return;
1096             case sz_long:
1097                printf ("\tULONG ccr;\n");
1098                printf ("\t__asm__(\"cmp %%2,%%1\n\tmov %%0,r15,lsr#24\n\teor %%0,%%0,#0x20\"\n"
1099                        "\t: \"=r\" (ccr) : \"r\" ((LONG)%s), \"r\" ((LONG)%s) : \"cc\" );\n", src, dst);
1100                printf ("\t*((UBYTE*)&regflags+3) = ccr;\n");
1101                /*printf ("\tprintf (\"%%08x %%08x %%08x\\n\", %s, %s, *((ULONG*)&regflags));\n", src, dst); */
1102                return;
1103            }
1104        }
1105        break;
1106    }
811   #endif
812      genflags_normal (type, size, value, src, dst);
813   }
# Line 1228 | Line 932 | static void gen_opcode (unsigned long in
932          genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
933          break;
934       case i_SBCD:
1231        /* Let's hope this works... */
935          genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
936          genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0);
937          start_brace ();
938          printf ("\tuae_u16 newv_lo = (dst & 0xF) - (src & 0xF) - (GET_XFLG ? 1 : 0);\n");
939          printf ("\tuae_u16 newv_hi = (dst & 0xF0) - (src & 0xF0);\n");
940 <        printf ("\tuae_u16 newv;\n");
941 <        printf ("\tint cflg;\n");
942 <        printf ("\tif (newv_lo > 9) { newv_lo-=6; newv_hi-=0x10; }\n");
943 <        printf ("\tnewv = newv_hi + (newv_lo & 0xF);");
944 <        printf ("\tSET_CFLG (cflg = (newv_hi & 0x1F0) > 0x90);\n");
940 >        printf ("\tuae_u16 newv, tmp_newv;\n");
941 >        printf ("\tint bcd = 0;\n");
942 >        printf ("\tnewv = tmp_newv = newv_hi + newv_lo;\n");
943 >        printf ("\tif (newv_lo & 0xF0) { newv -= 6; bcd = 6; };\n");
944 >        printf ("\tif ((((dst & 0xFF) - (src & 0xFF) - (GET_XFLG ? 1 : 0)) & 0x100) > 0xFF) { newv -= 0x60; }\n");
945 >        printf ("\tSET_CFLG ((((dst & 0xFF) - (src & 0xFF) - bcd - (GET_XFLG ? 1 : 0)) & 0x300) > 0xFF);\n");
946          duplicate_carry ();
947 <        printf ("\tif (cflg) newv -= 0x60;\n");
948 <        genflags (flag_zn, curi->size, "newv", "", "");
949 <        genflags (flag_sv, curi->size, "newv", "src", "dst");
947 >        /* Manual says bits NV are undefined though a real 68040 don't change them */
948 >        if (cpu_level >= xBCD_KEEPS_NV_FLAGS) {
949 >            if (next_cpu_level < xBCD_KEEPS_NV_FLAGS)
950 >                next_cpu_level = xBCD_KEEPS_NV_FLAGS - 1;
951 >            genflags (flag_z, curi->size, "newv", "", "");
952 >        }
953 >        else {
954 >            genflags (flag_zn, curi->size, "newv", "", "");
955 >            printf ("\tSET_VFLG ((tmp_newv & 0x80) != 0 && (newv & 0x80) == 0);\n");
956 >        }
957          genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
958          break;
959       case i_ADD:
# Line 1274 | Line 985 | static void gen_opcode (unsigned long in
985          start_brace ();
986          printf ("\tuae_u16 newv_lo = (src & 0xF) + (dst & 0xF) + (GET_XFLG ? 1 : 0);\n");
987          printf ("\tuae_u16 newv_hi = (src & 0xF0) + (dst & 0xF0);\n");
988 <        printf ("\tuae_u16 newv;\n");
988 >        printf ("\tuae_u16 newv, tmp_newv;\n");
989          printf ("\tint cflg;\n");
990 <        printf ("\tif (newv_lo > 9) { newv_lo +=6; }\n");
991 <        printf ("\tnewv = newv_hi + newv_lo;");
992 <        printf ("\tSET_CFLG (cflg = (newv & 0x1F0) > 0x90);\n");
1282 <        duplicate_carry ();
990 >        printf ("\tnewv = tmp_newv = newv_hi + newv_lo;\n");
991 >        printf ("\tif (newv_lo > 9) { newv += 6; }\n");
992 >        printf ("\tcflg = (newv & 0x3F0) > 0x90;\n");
993          printf ("\tif (cflg) newv += 0x60;\n");
994 <        genflags (flag_zn, curi->size, "newv", "", "");
995 <        genflags (flag_sv, curi->size, "newv", "src", "dst");
994 >        printf ("\tSET_CFLG (cflg);\n");
995 >        duplicate_carry ();
996 >        /* Manual says bits NV are undefined though a real 68040 don't change them */
997 >        if (cpu_level >= xBCD_KEEPS_NV_FLAGS) {
998 >            if (next_cpu_level < xBCD_KEEPS_NV_FLAGS)
999 >                next_cpu_level = xBCD_KEEPS_NV_FLAGS - 1;
1000 >            genflags (flag_z, curi->size, "newv", "", "");
1001 >        }
1002 >        else {
1003 >            genflags (flag_zn, curi->size, "newv", "", "");
1004 >            printf ("\tSET_VFLG ((tmp_newv & 0x80) == 0 && (newv & 0x80) != 0);\n");
1005 >        }
1006          genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
1007          break;
1008       case i_NEG:
# Line 1306 | Line 1026 | static void gen_opcode (unsigned long in
1026          printf ("\tuae_u16 newv_hi = - (src & 0xF0);\n");
1027          printf ("\tuae_u16 newv;\n");
1028          printf ("\tint cflg;\n");
1029 <        printf ("\tif (newv_lo > 9) { newv_lo-=6; newv_hi-=0x10; }\n");
1030 <        printf ("\tnewv = newv_hi + (newv_lo & 0xF);");
1031 <        printf ("\tSET_CFLG (cflg = (newv_hi & 0x1F0) > 0x90);\n");
1312 <        duplicate_carry();
1029 >        printf ("\tif (newv_lo > 9) { newv_lo -= 6; }\n");
1030 >        printf ("\tnewv = newv_hi + newv_lo;\n");
1031 >        printf ("\tcflg = (newv & 0x1F0) > 0x90;\n");
1032          printf ("\tif (cflg) newv -= 0x60;\n");
1033 <        genflags (flag_zn, curi->size, "newv", "", "");
1033 >        printf ("\tSET_CFLG (cflg);\n");
1034 >        duplicate_carry();
1035 >        /* Manual says bits NV are undefined though a real 68040 don't change them */
1036 >        if (cpu_level >= xBCD_KEEPS_NV_FLAGS) {
1037 >            if (next_cpu_level < xBCD_KEEPS_NV_FLAGS)
1038 >                next_cpu_level = xBCD_KEEPS_NV_FLAGS - 1;
1039 >            genflags (flag_z, curi->size, "newv", "", "");
1040 >        }
1041 >        else {
1042 >            genflags (flag_zn, curi->size, "newv", "", "");
1043 >        }
1044          genastore ("newv", curi->smode, "srcreg", curi->size, "src");
1045          break;
1046       case i_CLR:
# Line 1347 | Line 1076 | static void gen_opcode (unsigned long in
1076          else
1077              printf ("\tsrc &= 31;\n");
1078          printf ("\tdst ^= (1 << src);\n");
1079 <        printf ("\tSET_ZFLG ((dst & (1 << src)) >> src);\n");
1079 >        printf ("\tSET_ZFLG (((uae_u32)dst & (1 << src)) >> src);\n");
1080          genastore ("dst", curi->dmode, "dstreg", curi->size, "dst");
1081          break;
1082       case i_BCLR:
# Line 1518 | Line 1247 | static void gen_opcode (unsigned long in
1247              printf ("\tif ((format & 0xF000) == 0x0000) { break; }\n");
1248              printf ("\telse if ((format & 0xF000) == 0x1000) { ; }\n");
1249              printf ("\telse if ((format & 0xF000) == 0x2000) { m68k_areg(regs, 7) += 4; break; }\n");
1250 +            /* gb-- the next two lines are deleted in Bernie's gencpu.c */
1251              printf ("\telse if ((format & 0xF000) == 0x3000) { m68k_areg(regs, 7) += 4; break; }\n");
1252              printf ("\telse if ((format & 0xF000) == 0x7000) { m68k_areg(regs, 7) += 52; break; }\n");
1253              printf ("\telse if ((format & 0xF000) == 0x8000) { m68k_areg(regs, 7) += 50; break; }\n");
# Line 1606 | Line 1336 | static void gen_opcode (unsigned long in
1336          m68k_pc_offset = 0;
1337          break;
1338       case i_Bcc:
1339 +        if (0 && !using_prefetch && !using_exception_3 && (cpu_level >= 2)) {
1340 +        /* gb-- variant probably more favorable to compiler optimizations
1341 +                    also assumes no prefetch buffer is used
1342 +        Hmm, that would make sense with processors capable of conditional moves */
1343 +        if (curi->size == sz_long && next_cpu_level < 1)
1344 +                next_cpu_level = 1;
1345 +        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1346 +        printf ("\tm68k_incpc (cctrue(%d) ? ((uae_s32)src + 2) : %d);\n", curi->cc, m68k_pc_offset);
1347 +        m68k_pc_offset = 0;
1348 +        }
1349 +        else {
1350 +        /* original code for branch instructions */
1351          if (curi->size == sz_long) {
1352              if (cpu_level < 2) {
1353                  printf ("\tm68k_incpc(2);\n");
# Line 1629 | Line 1371 | static void gen_opcode (unsigned long in
1371              printf ("\t}\n");
1372              need_endlabel = 1;
1373          }
1632 #ifdef USE_COMPILER
1633        printf ("\tm68k_setpc_bcc(m68k_getpc() + 2 + (uae_s32)src);\n");
1634 #else
1374          printf ("\tm68k_incpc ((uae_s32)src + 2);\n");
1636 #endif
1375          fill_prefetch_0 ();
1376 <        printf ("\tgoto %s;\n", endlabelstr);
1376 >        printf ("return;\n");
1377          printf ("didnt_jump:;\n");
1378          need_endlabel = 1;
1379 +        }
1380          break;
1381       case i_LEA:
1382          genamode (curi->smode, "srcreg", curi->size, "src", 0, 0);
# Line 1665 | Line 1404 | static void gen_opcode (unsigned long in
1404              printf ("\t\t}\n");
1405              need_endlabel = 1;
1406          }
1668 #ifdef USE_COMPILER
1669        printf ("\t\t\tm68k_setpc_bcc(m68k_getpc() + (uae_s32)offs + 2);\n");
1670 #else
1407          printf ("\t\t\tm68k_incpc((uae_s32)offs + 2);\n");
1672 #endif
1408          fill_prefetch_0 ();
1409 <        printf ("\t\tgoto %s;\n", endlabelstr);
1409 >        printf ("return;\n");
1410          printf ("\t\t}\n");
1411          printf ("\t}\n");
1412          need_endlabel = 1;
# Line 1686 | Line 1421 | static void gen_opcode (unsigned long in
1421          printf ("\tuaecptr oldpc = m68k_getpc();\n");
1422          genamode (curi->smode, "srcreg", sz_word, "src", 1, 0);
1423          genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0);
1424 <        printf ("\tif(src == 0) { Exception(5,oldpc); goto %s; } else {\n", endlabelstr);
1424 >        sync_m68k_pc ();
1425 >        /* Clear V flag when dividing by zero - Alcatraz Odyssey demo depends
1426 >         * on this (actually, it's doing a DIVS).  */
1427 >        printf ("\tif (src == 0) { SET_VFLG (0); Exception (5, oldpc); goto %s; } else {\n", endlabelstr);
1428          printf ("\tuae_u32 newv = (uae_u32)dst / (uae_u32)(uae_u16)src;\n");
1429          printf ("\tuae_u32 rem = (uae_u32)dst %% (uae_u32)(uae_u16)src;\n");
1430          /* The N flag appears to be set each time there is an overflow.
# Line 1704 | Line 1442 | static void gen_opcode (unsigned long in
1442          printf ("\tuaecptr oldpc = m68k_getpc();\n");
1443          genamode (curi->smode, "srcreg", sz_word, "src", 1, 0);
1444          genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0);
1445 <        printf ("\tif(src == 0) { Exception(5,oldpc); goto %s; } else {\n", endlabelstr);
1445 >        sync_m68k_pc ();
1446 >        printf ("\tif (src == 0) { SET_VFLG (0); Exception(5,oldpc); goto %s; } else {\n", endlabelstr);
1447          printf ("\tuae_s32 newv = (uae_s32)dst / (uae_s32)(uae_s16)src;\n");
1448          printf ("\tuae_u16 rem = (uae_s32)dst %% (uae_s32)(uae_s16)src;\n");
1449          printf ("\tif ((newv & 0xffff8000) != 0 && (newv & 0xffff8000) != 0xffff8000) { SET_VFLG (1); SET_NFLG (1); SET_CFLG (0); } else\n\t{\n");
# Line 1765 | Line 1504 | static void gen_opcode (unsigned long in
1504              abort ();
1505          }
1506          printf ("\tSET_ZFLG (upper == reg || lower == reg);\n");
1507 <        printf ("\tSET_CFLG (lower <= upper ? reg < lower || reg > upper : reg > upper || reg < lower);\n");
1507 >        printf ("\tSET_CFLG_ALWAYS (lower <= upper ? reg < lower || reg > upper : reg > upper || reg < lower);\n");
1508          printf ("\tif ((extra & 0x800) && GET_CFLG) { Exception(6,oldpc); goto %s; }\n}\n", endlabelstr);
1509          need_endlabel = 1;
1510          break;
# Line 1964 | Line 1703 | static void gen_opcode (unsigned long in
1703          }
1704          printf ("\tcnt &= 63;\n");
1705          printf ("\tCLEAR_CZNV;\n");
1967        if (! source_is_imm1_8 (curi))
1968            force_range_for_rox ("cnt", curi->size);
1706          if (source_is_imm1_8 (curi))
1707              printf ("{");
1708 <        else
1708 >        else {
1709 >            force_range_for_rox ("cnt", curi->size);
1710              printf ("\tif (cnt > 0) {\n");
1711 +        }
1712          printf ("\tcnt--;\n");
1713          printf ("\t{\n\tuae_u32 carry;\n");
1714          printf ("\tuae_u32 loval = val >> (%d - cnt);\n", bit_size (curi->size) - 1);
# Line 1994 | Line 1733 | static void gen_opcode (unsigned long in
1733          }
1734          printf ("\tcnt &= 63;\n");
1735          printf ("\tCLEAR_CZNV;\n");
1997        if (! source_is_imm1_8 (curi))
1998            force_range_for_rox ("cnt", curi->size);
1736          if (source_is_imm1_8 (curi))
1737              printf ("{");
1738 <        else
1738 >        else {
1739 >            force_range_for_rox ("cnt", curi->size);
1740              printf ("\tif (cnt > 0) {\n");
1741 +        }
1742          printf ("\tcnt--;\n");
1743          printf ("\t{\n\tuae_u32 carry;\n");
1744          printf ("\tuae_u32 hival = (val << 1) | GET_XFLG;\n");
# Line 2155 | Line 1894 | static void gen_opcode (unsigned long in
1894          start_brace ();
1895          printf ("\tint regno = (src >> 12) & 15;\n");
1896          printf ("\tuae_u32 *regp = regs.regs + regno;\n");
1897 <        printf ("\tm68k_movec2(src & 0xFFF, regp);\n");
1897 >        printf ("\tif (! m68k_movec2(src & 0xFFF, regp)) goto %s;\n", endlabelstr);
1898          break;
1899       case i_MOVE2C:
1900          genamode (curi->smode, "srcreg", curi->size, "src", 1, 0);
1901          start_brace ();
1902          printf ("\tint regno = (src >> 12) & 15;\n");
1903          printf ("\tuae_u32 *regp = regs.regs + regno;\n");
1904 <        printf ("\tm68k_move2c(src & 0xFFF, regp);\n");
1904 >        printf ("\tif (! m68k_move2c(src & 0xFFF, regp)) goto %s;\n", endlabelstr);
1905          break;
1906       case i_CAS:
1907          {
# Line 2302 | Line 2041 | static void gen_opcode (unsigned long in
2041              printf ("\ttmp = (bf0 << (offset & 7)) | (bf1 >> (8 - (offset & 7)));\n");
2042          }
2043          printf ("\ttmp >>= (32 - width);\n");
2044 <        printf ("\tSET_NFLG (tmp & (1 << (width-1)) ? 1 : 0);\n");
2044 >        printf ("\tSET_NFLG_ALWAYS (tmp & (1 << (width-1)) ? 1 : 0);\n");
2045          printf ("\tSET_ZFLG (tmp == 0); SET_VFLG (0); SET_CFLG (0);\n");
2046          switch (curi->mnemo) {
2047           case i_BFTST:
# Line 2330 | Line 2069 | static void gen_opcode (unsigned long in
2069              break;
2070           case i_BFINS:
2071              printf ("\ttmp = m68k_dreg(regs, (extra >> 12) & 7);\n");
2072 +            printf ("\tSET_NFLG_ALWAYS (tmp & (1 << (width - 1)) ? 1 : 0);\n");
2073 +            printf ("\tSET_ZFLG (tmp == 0);\n");
2074              break;
2075           default:
2076              break;
# Line 2400 | Line 2141 | static void gen_opcode (unsigned long in
2141          genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0);
2142          sync_m68k_pc ();
2143          swap_opcode ();
2144 <        printf ("\tfpp_opp(opcode,extra);\n");
2144 >        printf ("\tfpuop_arithmetic(opcode, extra);\n");
2145          break;
2146       case i_FDBcc:
2147          genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0);
2148          sync_m68k_pc ();
2149          swap_opcode ();
2150 <        printf ("\tfdbcc_opp(opcode,extra);\n");
2150 >        printf ("\tfpuop_dbcc(opcode, extra);\n");
2151          break;
2152       case i_FScc:
2153          genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0);
2154          sync_m68k_pc ();
2155          swap_opcode ();
2156 <        printf ("\tfscc_opp(opcode,extra);\n");
2156 >        printf ("\tfpuop_scc(opcode,extra);\n");
2157          break;
2158       case i_FTRAPcc:
2159          sync_m68k_pc ();
# Line 2422 | Line 2163 | static void gen_opcode (unsigned long in
2163              genamode (curi->smode, "srcreg", curi->size, "dummy", 1, 0);
2164          sync_m68k_pc ();
2165          swap_opcode ();
2166 <        printf ("\tftrapcc_opp(opcode,oldpc);\n");
2166 >        printf ("\tfpuop_trapcc(opcode,oldpc);\n");
2167          break;
2168       case i_FBcc:
2169          sync_m68k_pc ();
# Line 2431 | Line 2172 | static void gen_opcode (unsigned long in
2172          genamode (curi->dmode, "srcreg", curi->size, "extra", 1, 0);
2173          sync_m68k_pc ();
2174          swap_opcode ();
2175 <        printf ("\tfbcc_opp(opcode,pc,extra);\n");
2175 >        printf ("\tfpuop_bcc(opcode,pc,extra);\n");
2176          break;
2177       case i_FSAVE:
2178          sync_m68k_pc ();
2179          swap_opcode ();
2180 <        printf ("\tfsave_opp(opcode);\n");
2180 >        printf ("\tfpuop_save(opcode);\n");
2181          break;
2182       case i_FRESTORE:
2183          sync_m68k_pc ();
2184          swap_opcode ();
2185 <        printf ("\tfrestore_opp(opcode);\n");
2185 >        printf ("\tfpuop_restore(opcode);\n");
2186          break;
2187       case i_CINVL:
2188       case i_CINVP:
2189       case i_CINVA:
2190 +        /* gb-- srcreg now contains the cache field */
2191 +        printf ("\tif (srcreg&0x2)\n");
2192 +        printf ("\t\tflush_icache(%d);\n", 30 + ((opcode >> 3) & 3));
2193 +        break;
2194       case i_CPUSHL:
2195       case i_CPUSHP:
2196       case i_CPUSHA:
2197 +        /* gb-- srcreg now contains the cache field */
2198 +        printf ("\tif (srcreg&0x2)\n");
2199 +        printf ("\t\tflush_icache(%d);\n", 40 + ((opcode >> 3) & 3));
2200          break;
2201       case i_MOVE16:
2202          if ((opcode & 0xfff8) == 0xf620) {
# Line 2486 | Line 2234 | static void gen_opcode (unsigned long in
2234          swap_opcode ();
2235          printf ("\tmmu_op(opcode,extra);\n");
2236          break;
2237 +        
2238 +        case i_EMULOP_RETURN:
2239 +        printf ("\tm68k_emulop_return();\n");
2240 +        m68k_pc_offset = 0;
2241 +        break;
2242 +        
2243 +        case i_EMULOP:
2244 +        printf ("\n");
2245 +        swap_opcode ();
2246 +        printf ("\tm68k_emulop(opcode);\n");
2247 +        break;
2248 +        
2249       default:
2250          abort ();
2251          break;
# Line 2497 | Line 2257 | static void gen_opcode (unsigned long in
2257   static void generate_includes (FILE * f)
2258   {
2259      fprintf (f, "#include \"sysdeps.h\"\n");
2260 +        
2261      fprintf (f, "#include \"m68k.h\"\n");
2262      fprintf (f, "#include \"memory.h\"\n");
2263      fprintf (f, "#include \"readcpu.h\"\n");
2264      fprintf (f, "#include \"newcpu.h\"\n");
2265 +    fprintf (f, "#include \"compiler/compemu.h\"\n");
2266 +    fprintf (f, "#include \"fpu/fpu.h\"\n");
2267      fprintf (f, "#include \"cputbl.h\"\n");
2268 +        
2269 +        fprintf (f, "#define SET_CFLG_ALWAYS(x) SET_CFLG(x)\n");
2270 +        fprintf (f, "#define SET_NFLG_ALWAYS(x) SET_NFLG(x)\n");
2271 +        fprintf (f, "#define CPUFUNC_FF(x) x##_ff\n");
2272 +        fprintf (f, "#define CPUFUNC_NF(x) x##_nf\n");
2273 +        fprintf (f, "#define CPUFUNC(x) CPUFUNC_FF(x)\n");
2274 +        
2275 +        fprintf (f, "#ifdef NOFLAGS\n");
2276 +        fprintf (f, "# include \"noflags.h\"\n");
2277 +        fprintf (f, "#endif\n");
2278   }
2279  
2280   static int postfix;
2281  
2282   static void generate_one_opcode (int rp)
2283   {
2511    int i;
2284      uae_u16 smsk, dmsk;
2285      long int opcode = opcode_map[rp];
2286 +    const char *opcode_str;
2287  
2288      if (table68k[opcode].mnemo == i_ILLG
2289          || table68k[opcode].clev > cpu_level)
2290          return;
2291  
2519    for (i = 0; lookuptab[i].name[0]; i++) {
2520        if (table68k[opcode].mnemo == lookuptab[i].mnemo)
2521            break;
2522    }
2523
2292      if (table68k[opcode].handler != -1)
2293          return;
2294  
2295 +    opcode_str = get_instruction_string (opcode);
2296 +
2297      if (opcode_next_clev[rp] != cpu_level) {
2298 <        fprintf (stblfile, "{ op_%lx_%d, 0, %ld }, /* %s */\n", opcode, opcode_last_postfix[rp],
2299 <                 opcode, lookuptab[i].name);
2298 >        if (table68k[opcode].flagdead == 0)
2299 >        /* force to the "ff" variant since the instruction doesn't set at all the condition codes */
2300 >        fprintf (stblfile, "{ CPUFUNC_FF(op_%lx_%d), 0, %ld }, /* %s */\n", opcode, opcode_last_postfix[rp],
2301 >                 opcode, opcode_str);
2302 >        else
2303 >        fprintf (stblfile, "{ CPUFUNC(op_%lx_%d), 0, %ld }, /* %s */\n", opcode, opcode_last_postfix[rp],
2304 >                 opcode, opcode_str);
2305          return;
2306      }
2307 <    fprintf (stblfile, "{ op_%lx_%d, 0, %ld }, /* %s */\n", opcode, postfix, opcode, lookuptab[i].name);
2308 <    fprintf (headerfile, "extern cpuop_func op_%lx_%d;\n", opcode, postfix);
2309 <    printf ("void REGPARAM2 op_%lx_%d(uae_u32 opcode) /* %s */\n{\n", opcode, postfix, lookuptab[i].name);
2307 >        
2308 >        if (table68k[opcode].flagdead == 0)
2309 >        /* force to the "ff" variant since the instruction doesn't set at all the condition codes */
2310 >    fprintf (stblfile, "{ CPUFUNC_FF(op_%lx_%d), 0, %ld }, /* %s */\n", opcode, postfix, opcode, opcode_str);
2311 >        else
2312 >    fprintf (stblfile, "{ CPUFUNC(op_%lx_%d), 0, %ld }, /* %s */\n", opcode, postfix, opcode, opcode_str);
2313 >
2314 >    fprintf (headerfile, "extern cpuop_func op_%lx_%d_nf;\n", opcode, postfix);
2315 >    fprintf (headerfile, "extern cpuop_func op_%lx_%d_ff;\n", opcode, postfix);
2316 >        
2317 >        /* gb-- The "nf" variant for an instruction that doesn't set the condition
2318 >           codes at all is the same as the "ff" variant, so we don't need the "nf"
2319 >           variant to be compiled since it is mapped to the "ff" variant in the
2320 >           smalltbl. */
2321 >        if (table68k[opcode].flagdead == 0)
2322 >        printf ("#ifndef NOFLAGS\n");
2323 >
2324 >        printf ("void REGPARAM2 CPUFUNC(op_%lx_%d)(uae_u32 opcode) /* %s */\n{\n", opcode, postfix, opcode_str);
2325 >        printf ("\tcpuop_begin();\n");
2326  
2327      switch (table68k[opcode].stype) {
2328       case 0: smsk = 7; break;
# Line 2540 | Line 2331 | static void generate_one_opcode (int rp)
2331       case 3: smsk = 7; break;
2332       case 4: smsk = 7; break;
2333       case 5: smsk = 63; break;
2334 +         case 6: smsk = 255; break;
2335           case 7: smsk = 3; break;
2336       default: abort ();
2337      }
# Line 2550 | Line 2342 | static void generate_one_opcode (int rp)
2342          && table68k[opcode].smode != imm && table68k[opcode].smode != imm0
2343          && table68k[opcode].smode != imm1 && table68k[opcode].smode != imm2
2344          && table68k[opcode].smode != absw && table68k[opcode].smode != absl
2345 <        && table68k[opcode].smode != PC8r && table68k[opcode].smode != PC16)
2345 >        && table68k[opcode].smode != PC8r && table68k[opcode].smode != PC16
2346 >        /* gb-- We don't want to fetch the EmulOp code since the EmulOp()
2347 >           routine uses the whole opcode value. Maybe all the EmulOps
2348 >           could be expanded out but I don't think it is an improvement */
2349 >        && table68k[opcode].stype != 6
2350 >        )
2351      {
2352          if (table68k[opcode].spos == -1) {
2353              if (((int) table68k[opcode].sreg) >= 128)
# Line 2646 | Line 2443 | static void generate_one_opcode (int rp)
2443      gen_opcode (opcode);
2444      if (need_endlabel)
2445          printf ("%s: ;\n", endlabelstr);
2446 +        printf ("\tcpuop_end();\n");
2447      printf ("}\n");
2448 +        if (table68k[opcode].flagdead == 0)
2449 +        printf ("\n#endif\n");
2450      opcode_next_clev[rp] = next_cpu_level;
2451      opcode_last_postfix[rp] = postfix;
2452   }
# Line 2673 | Line 2473 | static void generate_func (void)
2473                  opcode_next_clev[rp] = 0;
2474          }
2475          postfix = i;
2476 <        fprintf (stblfile, "struct cputbl op_smalltbl_%d[] = {\n", postfix);
2476 >        fprintf (stblfile, "struct cputbl CPUFUNC(op_smalltbl_%d)[] = {\n", postfix);
2477  
2478          /* sam: this is for people with low memory (eg. me :)) */
2479          printf ("\n"
# Line 2707 | Line 2507 | static void generate_func (void)
2507  
2508   int main (int argc, char **argv)
2509   {
2510 +    FILE *out;
2511      read_table68k ();
2512      do_merges ();
2513  
# Line 2720 | Line 2521 | int main (int argc, char **argv)
2521       * cputbl.h that way), but cpuopti can't cope.  That could be fixed, but
2522       * I don't dare to touch the 68k version.  */
2523  
2524 <    headerfile = fopen ("cputbl.h", "wb");
2525 <    stblfile = fopen ("cpustbl.cpp", "wb");
2526 <    freopen ("cpuemu.cpp", "wb", stdout);
2524 >    headerfile = fopen ("cputbl.h", "w");
2525 >    stblfile = fopen ("cpustbl.cpp", "w");
2526 >    out = freopen ("cpuemu.cpp", "w", stdout);
2527  
2528      generate_includes (stdout);
2529      generate_includes (stblfile);
# Line 2730 | Line 2531 | int main (int argc, char **argv)
2531      generate_func ();
2532  
2533      free (table68k);
2534 +    fclose (headerfile);
2535 +    fclose (stblfile);
2536 +    fflush (out);
2537      return 0;
2538   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines