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.1.1.1 by cebix, 1999-10-03T14:16:26Z 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 24 | Line 39
39   #include "sysdeps.h"
40   #include "readcpu.h"
41  
42 + #if defined(SPARC_V8_ASSEMBLY) || defined(SPARC_V9_ASSEMBLY)
43 + #define SPARC_ASSEMBLY 0
44 + #endif
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 55 | Line 77 | static void read_counts (void)
77      if (file) {
78          fscanf (file, "Total: %lu\n", &total);
79          while (fscanf (file, "%lx: %lu %s\n", &opcode, &count, name) == 3) {
80 <            opcode_next_clev[nr] = 3;
80 >            opcode_next_clev[nr] = 4;
81              opcode_last_postfix[nr] = -1;
82              opcode_map[nr++] = opcode;
83              counts[opcode] = count;
# Line 68 | Line 90 | static void read_counts (void)
90          if (table68k[opcode].handler == -1 && table68k[opcode].mnemo != i_ILLG
91              && counts[opcode] == 0)
92          {
93 <            opcode_next_clev[nr] = 3;
93 >            opcode_next_clev[nr] = 4;
94              opcode_last_postfix[nr] = -1;
95              opcode_map[nr++] = opcode;
96              counts[opcode] = count;
# Line 217 | Line 239 | static void sync_m68k_pc (void)
239   }
240  
241   /* getv == 1: fetch data; getv != 0: check for odd address. If movem != 0,
242 < * the calling routine handles Apdi and Aipi modes. */
242 > * the calling routine handles Apdi and Aipi modes.
243 > * gb-- movem == 2 means the same thing but for a MOVE16 instruction */
244   static void genamode (amodes mode, char *reg, wordsizes size, char *name, int getv, int movem)
245   {
246      start_brace ();
# Line 228 | Line 251 | static void genamode (amodes mode, char
251          if (getv == 1)
252              switch (size) {
253               case sz_byte:
254 < #ifdef AMIGA
254 > #if defined(AMIGA) && !defined(WARPUP)
255                  /* sam: I don't know why gcc.2.7.2.1 produces a code worse */
256                  /* if it is not done like that: */
257                  printf ("\tuae_s8 %s = ((uae_u8*)&m68k_dreg(regs, %s))[3];\n", name, reg);
# Line 237 | Line 260 | static void genamode (amodes mode, char
260   #endif
261                  break;
262               case sz_word:
263 < #ifdef AMIGA
263 > #if defined(AMIGA) && !defined(WARPUP)
264                  printf ("\tuae_s16 %s = ((uae_s16*)&m68k_dreg(regs, %s))[1];\n", name, reg);
265   #else
266                  printf ("\tuae_s16 %s = m68k_dreg(regs, %s);\n", name, reg);
# Line 563 | 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 617 | 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 638 | 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 671 | 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 710 | 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 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;
720
751       default:
752          break;
753      }
# Line 725 | 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      }
780 #elif defined(M68K_FLAG_OPT)
781    /* sam: here I'm cloning what X86_ASSEMBLY does */
782 #define EXT(size)  (size==sz_byte?"b":(size==sz_word?"w":"l"))
783 #define CAST(size) (size==sz_byte?"uae_s8":(size==sz_word?"uae_s16":"uae_s32"))
784    switch (type) {
785     case flag_add:
786     case flag_sub:
787        start_brace ();
788        printf ("\tuae_u32 %s;\n", value);
789        break;
790
791     default:
792        break;
793    }
794
795    switch (type) {
796     case flag_logical:
797        if (strcmp (value, "0") == 0) {
798            printf ("\t*(uae_u16 *)&regflags = 4;\n");  /* Z = 1 */
799        } else {
800            printf ("\tm68k_flag_tst (%s, (%s)(%s));\n",
801                    EXT (size), CAST (size), value);
802        }
803        return;
804
805     case flag_add:
806        printf ("\t{uae_u16 ccr;\n");
807        printf ("\tm68k_flag_add (%s, (%s)%s, (%s)(%s), (%s)(%s));\n",
808                EXT (size), CAST (size), value, CAST (size), src, CAST (size), dst);
809        printf ("\t((uae_u16*)&regflags)[1]=((uae_u16*)&regflags)[0]=ccr;}\n");
810        return;
811
812     case flag_sub:
813        printf ("\t{uae_u16 ccr;\n");
814        printf ("\tm68k_flag_sub (%s, (%s)%s, (%s)(%s), (%s)(%s));\n",
815                EXT (size), CAST (size), value, CAST (size), src, CAST (size), dst);
816        printf ("\t((uae_u16*)&regflags)[1]=((uae_u16*)&regflags)[0]=ccr;}\n");
817        return;
818
819     case flag_cmp:
820        printf ("\tm68k_flag_cmp (%s, (%s)(%s), (%s)(%s));\n",
821                EXT (size), CAST (size), src, CAST (size), dst);
822        return;
823
824     default:
825        break;
826    }
827 #elif defined(ACORN_FLAG_OPT) && defined(__GNUC_MINOR__)
828 /*
829 * This is new. Might be quite buggy.
830 */
831    switch (type) {
832     case flag_av:
833     case flag_sv:
834     case flag_zn:
835     case flag_addx:
836     case flag_subx:
837        break;
838
839     case flag_logical:
840        if (strcmp (value, "0") == 0) {
841            /* v=c=n=0 z=1 */
842            printf ("\t*(ULONG*)&regflags = 0x40000000;\n");
843            return;
844        } else {
845            start_brace ();
846            switch (size) {
847             case sz_byte:
848                printf ("\tUBYTE ccr;\n");
849                printf ("\tULONG shift;\n");
850                printf ("\t__asm__(\"mov %%2,%%1,lsl#24\n\ttst %%2,%%2\n\tmov %%0,r15,lsr#24\n\tbic %%0,%%0,#0x30\"\n"
851                        "\t: \"=r\" (ccr) : \"r\" (%s), \"r\" (shift) : \"cc\" );\n", value);
852                printf ("\t*((UBYTE*)&regflags+3) = ccr;\n");
853                return;
854             case sz_word:
855                printf ("\tUBYTE ccr;\n");
856                printf ("\tULONG shift;\n");
857                printf ("\t__asm__(\"mov %%2,%%1,lsl#16\n\ttst %%2,%%2\n\tmov %%0,r15,lsr#24\n\tbic %%0,%%0,#0x30\"\n"
858                        "\t: \"=r\" (ccr) : \"r\" ((WORD)%s), \"r\" (shift) : \"cc\" );\n", value);
859                printf ("\t*((UBYTE*)&regflags+3) = ccr;\n");
860                return;
861             case sz_long:
862                printf ("\tUBYTE ccr;\n");
863                printf ("\t__asm__(\"tst %%1,%%1\n\tmov %%0,r15,lsr#24\n\tbic %%0,%%0,#0x30\"\n"
864                        "\t: \"=r\" (ccr) : \"r\" ((LONG)%s) : \"cc\" );\n", value);
865                printf ("\t*((UBYTE*)&regflags+3) = ccr;\n");
866                return;
867            }
868        }
869        break;
870     case flag_add:
871        if (strcmp (dst, "0") == 0) {
872            printf ("/* Error! Hier muss Peter noch was machen !!! (ADD-Flags) */");
873        } else {
874            start_brace ();
875            switch (size) {
876             case sz_byte:
877                printf ("\tULONG ccr, shift, %s;\n", value);
878                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"
879                        "\t: \"=r\" (%s), \"=r\" (ccr) : \"r\" (%s), \"r\" (%s), \"r\" (shift) : \"cc\" );\n", value, src, dst);
880                printf ("\t*(ULONG*)&regflags = ccr;\n");
881                return;
882             case sz_word:
883                printf ("\tULONG ccr, shift, %s;\n", value);
884                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"
885                        "\t: \"=r\" (%s), \"=r\" (ccr) : \"r\" ((WORD)%s), \"r\" ((WORD)%s), \"r\" (shift) : \"cc\" );\n", value, src, dst);
886                printf ("\t*(ULONG*)&regflags = ccr;\n");
887                return;
888             case sz_long:
889                printf ("\tULONG ccr, %s;\n", value);
890                printf ("\t__asm__(\"adds %%0,%%3,%%2\n\tmov %%1,r15\n\torr %%1,%%1,%%1,lsr#29\"\n"
891                        "\t: \"=r\" (%s), \"=r\" (ccr) : \"r\" ((LONG)%s), \"r\" ((LONG)%s) : \"cc\" );\n", value, src, dst);
892                printf ("\t*(ULONG*)&regflags = ccr;\n");
893                return;
894            }
895        }
896        break;
897     case flag_sub:
898        if (strcmp (dst, "0") == 0) {
899            printf ("/* Error! Hier muss Peter noch was machen !!! (SUB-Flags) */");
900        } else {
901            start_brace ();
902            switch (size) {
903             case sz_byte:
904                printf ("\tULONG ccr, shift, %s;\n", value);
905                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"
906                        "\t: \"=r\" (%s), \"=r\" (ccr) : \"r\" (%s), \"r\" (%s), \"r\" (shift) : \"cc\" );\n", value, src, dst);
907                printf ("\t*(ULONG*)&regflags = ccr;\n");
908                return;
909             case sz_word:
910                printf ("\tULONG ccr, shift, %s;\n", value);
911                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"
912                        "\t: \"=r\" (%s), \"=r\" (ccr) : \"r\" ((WORD)%s), \"r\" ((WORD)%s), \"r\" (shift) : \"cc\" );\n", value, src, dst);
913                printf ("\t*(ULONG*)&regflags = ccr;\n");
914                return;
915             case sz_long:
916                printf ("\tULONG ccr, %s;\n", value);
917                printf ("\t__asm__(\"subs %%0,%%3,%%2\n\tmov %%1,r15\n\teor %%1,%%1,#0x20000000\n\torr %%1,%%1,%%1,lsr#29\"\n"
918                        "\t: \"=r\" (%s), \"=r\" (ccr) : \"r\" ((LONG)%s), \"r\" ((LONG)%s) : \"cc\" );\n", value, src, dst);
919                printf ("\t*(ULONG*)&regflags = ccr;\n");
920                return;
921            }
922        }
923        break;
924     case flag_cmp:
925        if (strcmp (dst, "0") == 0) {
926            printf ("/*Error! Hier muss Peter noch was machen !!! (CMP-Flags)*/");
927        } else {
928            start_brace ();
929            switch (size) {
930             case sz_byte:
931                printf ("\tULONG shift, ccr;\n");
932                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"
933                        "\t: \"=r\" (ccr) : \"r\" (%s), \"r\" (%s), \"r\" (shift) : \"cc\" );\n", src, dst);
934                printf ("\t*((UBYTE*)&regflags+3) = ccr;\n");
935                return;
936             case sz_word:
937                printf ("\tULONG shift, ccr;\n");
938                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"
939                        "\t: \"=r\" (ccr) : \"r\" ((WORD)%s), \"r\" ((WORD)%s), \"r\" (shift) : \"cc\" );\n", src, dst);
940                printf ("\t*((UBYTE*)&regflags+3) = ccr;\n");
941                return;
942             case sz_long:
943                printf ("\tULONG ccr;\n");
944                printf ("\t__asm__(\"cmp %%2,%%1\n\tmov %%0,r15,lsr#24\n\teor %%0,%%0,#0x20\"\n"
945                        "\t: \"=r\" (ccr) : \"r\" ((LONG)%s), \"r\" ((LONG)%s) : \"cc\" );\n", src, dst);
946                printf ("\t*((UBYTE*)&regflags+3) = ccr;\n");
947                /*printf ("\tprintf (\"%%08x %%08x %%08x\\n\", %s, %s, *((ULONG*)&regflags));\n", src, dst); */
948                return;
949            }
950        }
951        break;
952    }
811   #endif
812      genflags_normal (type, size, value, src, dst);
813   }
# Line 1074 | Line 932 | static void gen_opcode (unsigned long in
932          genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
933          break;
934       case i_SBCD:
1077        /* 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 1120 | 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");
1128 <        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 1152 | 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");
1158 <        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 1193 | 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 1364 | 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");
1254              printf ("\telse if ((format & 0xF000) == 0x9000) { m68k_areg(regs, 7) += 12; break; }\n");
1255              printf ("\telse if ((format & 0xF000) == 0xa000) { m68k_areg(regs, 7) += 24; break; }\n");
# Line 1380 | Line 1266 | static void gen_opcode (unsigned long in
1266          m68k_pc_offset = 0;
1267          break;
1268       case i_RTD:
1383        printf ("\tcompiler_flush_jsr_stack();\n");
1269          genamode (Aipi, "7", sz_long, "pc", 1, 0);
1270          genamode (curi->smode, "srcreg", curi->size, "offs", 1, 0);
1271          printf ("\tm68k_areg(regs, 7) += offs;\n");
# Line 1414 | Line 1299 | static void gen_opcode (unsigned long in
1299          need_endlabel = 1;
1300          break;
1301       case i_RTR:
1417        printf ("\tcompiler_flush_jsr_stack();\n");
1302          printf ("\tMakeSR();\n");
1303          genamode (Aipi, "7", sz_word, "sr", 1, 0);
1304          genamode (Aipi, "7", sz_long, "pc", 1, 0);
# Line 1452 | 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 1475 | Line 1371 | static void gen_opcode (unsigned long in
1371              printf ("\t}\n");
1372              need_endlabel = 1;
1373          }
1478 #ifdef USE_COMPILER
1479        printf ("\tm68k_setpc_bcc(m68k_getpc() + 2 + (uae_s32)src);\n");
1480 #else
1374          printf ("\tm68k_incpc ((uae_s32)src + 2);\n");
1482 #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 1511 | Line 1404 | static void gen_opcode (unsigned long in
1404              printf ("\t\t}\n");
1405              need_endlabel = 1;
1406          }
1514 #ifdef USE_COMPILER
1515        printf ("\t\t\tm68k_setpc_bcc(m68k_getpc() + (uae_s32)offs + 2);\n");
1516 #else
1407          printf ("\t\t\tm68k_incpc((uae_s32)offs + 2);\n");
1518 #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 1532 | 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 1550 | 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 1611 | 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 1810 | Line 1703 | static void gen_opcode (unsigned long in
1703          }
1704          printf ("\tcnt &= 63;\n");
1705          printf ("\tCLEAR_CZNV;\n");
1813        if (! source_is_imm1_8 (curi))
1814            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 1840 | Line 1733 | static void gen_opcode (unsigned long in
1733          }
1734          printf ("\tcnt &= 63;\n");
1735          printf ("\tCLEAR_CZNV;\n");
1843        if (! source_is_imm1_8 (curi))
1844            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 2001 | 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 2148 | 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 2176 | 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 2246 | 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 2268 | 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 2277 | 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) {
2203 >                /* MOVE16 (Ax)+,(Ay)+ */
2204 >                printf ("\tuaecptr mems = m68k_areg(regs, srcreg) & ~15, memd;\n");
2205 >                printf ("\tdstreg = (%s >> 12) & 7;\n", gen_nextiword());
2206 >                printf ("\tmemd = m68k_areg(regs, dstreg) & ~15;\n");
2207 >                printf ("\tput_long(memd, get_long(mems));\n");
2208 >                printf ("\tput_long(memd+4, get_long(mems+4));\n");
2209 >                printf ("\tput_long(memd+8, get_long(mems+8));\n");
2210 >                printf ("\tput_long(memd+12, get_long(mems+12));\n");
2211 >                printf ("\tif (srcreg != dstreg)\n");
2212 >                printf ("\tm68k_areg(regs, srcreg) += 16;\n");
2213 >                printf ("\tm68k_areg(regs, dstreg) += 16;\n");
2214 >        }
2215 >        else {
2216 >                /* Other variants */
2217 >                genamode (curi->smode, "srcreg", curi->size, "mems", 0, 2);
2218 >                genamode (curi->dmode, "dstreg", curi->size, "memd", 0, 2);
2219 >                printf ("\tmemsa &= ~15;\n");
2220 >                printf ("\tmemda &= ~15;\n");
2221 >                printf ("\tput_long(memda, get_long(memsa));\n");
2222 >                printf ("\tput_long(memda+4, get_long(memsa+4));\n");
2223 >                printf ("\tput_long(memda+8, get_long(memsa+8));\n");
2224 >                printf ("\tput_long(memda+12, get_long(memsa+12));\n");
2225 >                if ((opcode & 0xfff8) == 0xf600)
2226 >                printf ("\tm68k_areg(regs, srcreg) += 16;\n");
2227 >                else if ((opcode & 0xfff8) == 0xf608)
2228 >                printf ("\tm68k_areg(regs, dstreg) += 16;\n");
2229 >        }
2230          break;
2231       case i_MMUOP:
2232          genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0);
# Line 2295 | 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 2306 | 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.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   {
2321    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  
2329    for (i = 0; lookuptab[i].name[0]; i++) {
2330        if (table68k[opcode].mnemo == lookuptab[i].mnemo)
2331            break;
2332    }
2333
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 ("unsigned long 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 2350 | 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      }
2338      dmsk = 7;
# Line 2359 | 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 2455 | Line 2443 | static void generate_one_opcode (int rp)
2443      gen_opcode (opcode);
2444      if (need_endlabel)
2445          printf ("%s: ;\n", endlabelstr);
2446 <    printf ("return %d;\n", insn_n_cycles);
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 2467 | Line 2457 | static void generate_func (void)
2457  
2458      using_prefetch = 0;
2459      using_exception_3 = 0;
2460 <    for (i = 0; i < 5; i++) {
2461 <        cpu_level = 3 - i;
2462 <        if (i == 4) {
2460 > #if !USE_PREFETCH_BUFFER
2461 >        /* gb-- No need for a prefetch buffer, nor exception 3 handling */
2462 >        /* Anyway, Basilisk2 does not use the op_smalltbl_5 table... */
2463 >    for (i = 0; i <= 4; i++) {
2464 > #else
2465 >    for (i = 0; i < 6; i++) {
2466 > #endif
2467 >        cpu_level = 4 - i;
2468 >        if (i == 5) {
2469              cpu_level = 0;
2470              using_prefetch = 1;
2471              using_exception_3 = 1;
# Line 2477 | 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 2507 | Line 2503 | static void generate_func (void)
2503  
2504          fprintf (stblfile, "{ 0, 0, 0 }};\n");
2505      }
2510
2506   }
2507  
2508   int main (int argc, char **argv)
2509   {
2510 +    FILE *out;
2511      read_table68k ();
2512      do_merges ();
2513  
# Line 2525 | 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 2535 | 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