2 // Inline functions used by cpuemu.c
4 // by Bernd Schmidt, Thomas Huth, and James Hammons
6 // Since inline functions have to be in a header, we have them all defined
7 // here, in one place to make finding them easy.
15 STATIC_INLINE int cctrue(const int cc)
19 case 0: return 1; /* T */
20 case 1: return 0; /* F */
21 case 2: return !CFLG && !ZFLG; /* HI */
22 case 3: return CFLG || ZFLG; /* LS */
23 case 4: return !CFLG; /* CC */
24 case 5: return CFLG; /* CS */
25 case 6: return !ZFLG; /* NE */
26 case 7: return ZFLG; /* EQ */
27 case 8: return !VFLG; /* VC */
28 case 9: return VFLG; /* VS */
29 case 10: return !NFLG; /* PL */
30 case 11: return NFLG; /* MI */
31 case 12: return NFLG == VFLG; /* GE */
32 case 13: return NFLG != VFLG; /* LT */
33 case 14: return !ZFLG && (NFLG == VFLG); /* GT */
34 case 15: return ZFLG || (NFLG != VFLG); /* LE */
41 //no #define m68k_incpc(o) (regs.pc_p += (o))
42 #define m68k_incpc(o) (regs.pc += (o))
44 STATIC_INLINE void m68k_setpc(uint32_t newpc)
46 //This is only done here... (get_real_address())
47 // regs.pc_p = regs.pc_oldp = get_real_address(newpc);
51 #define m68k_setpc_rte m68k_setpc
53 STATIC_INLINE uint32_t m68k_getpc(void)
55 // return regs.pc + ((char *)regs.pc_p - (char *)regs.pc_oldp);
60 STATIC_INLINE uint32_t m68k_getpc_p(uint8_t * p)
62 return regs.pc + ((char *)p - (char *)regs.pc_oldp);
66 STATIC_INLINE void m68k_setstopped(int stop)
69 regs.remainingCycles = 0;
71 //But trace instructions are only on >68000 cpus, so this is bogus.
73 /* A traced STOP instruction drops through immediately without
75 if (stop && (regs.spcflags & SPCFLAG_DOTRACE) == 0)
76 regs.spcflags |= SPCFLAG_STOP;
80 STATIC_INLINE void m68k_do_rts(void)
82 m68k_setpc(m68k_read_memory_32(m68k_areg(regs, 7)));
83 m68k_areg(regs, 7) += 4;
86 STATIC_INLINE void m68k_do_bsr(uint32_t oldpc, int32_t offset)
88 m68k_areg(regs, 7) -= 4;
89 m68k_write_memory_32(m68k_areg(regs, 7), oldpc);
93 STATIC_INLINE void m68k_do_jsr(uint32_t oldpc, uint32_t dest)
95 m68k_areg(regs, 7) -= 4;
96 m68k_write_memory_32(m68k_areg(regs, 7), oldpc);
101 //These do_get_mem_* functions are only used in newcpu...
102 //What it does is use a pointer to make instruction fetching quicker,
103 //though it probably leads to more problems than it solves. Something to
104 //decide using a profiler...
105 #define get_ibyte(o) do_get_mem_byte(regs.pc_p + (o) + 1)
106 #define get_iword(o) do_get_mem_word(regs.pc_p + (o))
107 #define get_ilong(o) do_get_mem_long(regs.pc_p + (o))
109 // For now, we'll punt this crap...
110 // (Also, notice that the byte read is at address + 1...)
111 #define get_ibyte(o) m68k_read_memory_8(regs.pc + (o) + 1)
112 #define get_iword(o) m68k_read_memory_16(regs.pc + (o))
113 #define get_ilong(o) m68k_read_memory_32(regs.pc + (o))
116 // We don't use this crap, so let's comment out for now...
117 STATIC_INLINE void refill_prefetch(uint32_t currpc, uint32_t offs)
120 uint32_t t = (currpc + offs) & ~1;
121 int32_t pc_p_offs = t - currpc;
122 uint8_t * ptr = regs.pc_p + pc_p_offs;
125 #ifdef UNALIGNED_PROFITABLE
126 r = *(uint32_t *)ptr;
129 r = do_get_mem_long(ptr);
130 do_put_mem_long(®s.prefetch, r);
132 /* printf ("PC %lx T %lx PCPOFFS %d R %lx\n", currpc, t, pc_p_offs, r); */
133 regs.prefetch_pc = t;
137 STATIC_INLINE uint32_t get_ibyte_prefetch(int32_t o)
140 uint32_t currpc = m68k_getpc();
141 uint32_t addr = currpc + o + 1;
142 uint32_t offs = addr - regs.prefetch_pc;
146 refill_prefetch(currpc, o + 1);
147 offs = addr - regs.prefetch_pc;
150 uint32_t v = do_get_mem_byte(((uint8_t *)®s.prefetch) + offs);
153 refill_prefetch(currpc, 2);
155 /* printf ("get_ibyte PC %lx ADDR %lx OFFS %lx V %lx\n", currpc, addr, offs, v); */
162 STATIC_INLINE uint32_t get_iword_prefetch(int32_t o)
165 uint32_t currpc = m68k_getpc();
166 uint32_t addr = currpc + o;
167 uint32_t offs = addr - regs.prefetch_pc;
171 refill_prefetch(currpc, o);
172 offs = addr - regs.prefetch_pc;
175 uint32_t v = do_get_mem_word(((uint8_t *)®s.prefetch) + offs);
178 refill_prefetch(currpc, 2);
180 /* printf ("get_iword PC %lx ADDR %lx OFFS %lx V %lx\n", currpc, addr, offs, v); */
187 STATIC_INLINE uint32_t get_ilong_prefetch(int32_t o)
190 uint32_t v = get_iword_prefetch(o);
192 v |= get_iword_prefetch(o + 2);
199 STATIC_INLINE void fill_prefetch_0(void)
203 #define fill_prefetch_2 fill_prefetch_0
205 #endif // __INLINES_H__