2 // Inline functions used by cpuemu.c
4 // Since inline functions have to be in a header, we have them all defined
5 // here, in one place to make finding them easy.
13 STATIC_INLINE int cctrue(const int cc)
17 case 0: return 1; /* T */
18 case 1: return 0; /* F */
19 case 2: return !CFLG && !ZFLG; /* HI */
20 case 3: return CFLG || ZFLG; /* LS */
21 case 4: return !CFLG; /* CC */
22 case 5: return CFLG; /* CS */
23 case 6: return !ZFLG; /* NE */
24 case 7: return ZFLG; /* EQ */
25 case 8: return !VFLG; /* VC */
26 case 9: return VFLG; /* VS */
27 case 10: return !NFLG; /* PL */
28 case 11: return NFLG; /* MI */
29 case 12: return NFLG == VFLG; /* GE */
30 case 13: return NFLG != VFLG; /* LT */
31 case 14: return !ZFLG && (NFLG == VFLG); /* GT */
32 case 15: return ZFLG || (NFLG != VFLG); /* LE */
39 //no #define m68k_incpc(o) (regs.pc_p += (o))
40 #define m68k_incpc(o) (regs.pc += (o))
42 STATIC_INLINE void m68k_setpc(uint32_t newpc)
44 //This is only done here... (get_real_address())
45 // regs.pc_p = regs.pc_oldp = get_real_address(newpc);
49 #define m68k_setpc_rte m68k_setpc
51 STATIC_INLINE uint32_t m68k_getpc(void)
53 // return regs.pc + ((char *)regs.pc_p - (char *)regs.pc_oldp);
58 STATIC_INLINE uint32_t m68k_getpc_p(uint8_t * p)
60 return regs.pc + ((char *)p - (char *)regs.pc_oldp);
64 STATIC_INLINE void m68k_setstopped(int stop)
67 regs.remainingCycles = 0;
69 //But trace instructions are only on >68000 cpus, so this is bogus.
71 /* A traced STOP instruction drops through immediately without
73 if (stop && (regs.spcflags & SPCFLAG_DOTRACE) == 0)
74 regs.spcflags |= SPCFLAG_STOP;
78 STATIC_INLINE void m68k_do_rts(void)
80 m68k_setpc(m68k_read_memory_32(m68k_areg(regs, 7)));
81 m68k_areg(regs, 7) += 4;
84 STATIC_INLINE void m68k_do_bsr(uint32_t oldpc, int32_t offset)
86 m68k_areg(regs, 7) -= 4;
87 m68k_write_memory_32(m68k_areg(regs, 7), oldpc);
91 STATIC_INLINE void m68k_do_jsr(uint32_t oldpc, uint32_t dest)
93 m68k_areg(regs, 7) -= 4;
94 m68k_write_memory_32(m68k_areg(regs, 7), oldpc);
99 //These do_get_mem_* functions are only used in newcpu...
100 //What it does is use a pointer to make instruction fetching quicker,
101 //though it probably leads to more problems than it solves. Something to
102 //decide using a profiler...
103 #define get_ibyte(o) do_get_mem_byte(regs.pc_p + (o) + 1)
104 #define get_iword(o) do_get_mem_word(regs.pc_p + (o))
105 #define get_ilong(o) do_get_mem_long(regs.pc_p + (o))
107 // For now, we'll punt this crap...
108 // (Also, notice that the byte read is at address + 1...)
109 #define get_ibyte(o) m68k_read_memory_8(regs.pc + (o) + 1)
110 #define get_iword(o) m68k_read_memory_16(regs.pc + (o))
111 #define get_ilong(o) m68k_read_memory_32(regs.pc + (o))
114 // We don't use this crap, so let's comment out for now...
115 STATIC_INLINE void refill_prefetch(uint32_t currpc, uint32_t offs)
118 uint32_t t = (currpc + offs) & ~1;
119 int32_t pc_p_offs = t - currpc;
120 uint8_t * ptr = regs.pc_p + pc_p_offs;
123 #ifdef UNALIGNED_PROFITABLE
124 r = *(uint32_t *)ptr;
127 r = do_get_mem_long(ptr);
128 do_put_mem_long(®s.prefetch, r);
130 /* printf ("PC %lx T %lx PCPOFFS %d R %lx\n", currpc, t, pc_p_offs, r); */
131 regs.prefetch_pc = t;
135 STATIC_INLINE uint32_t get_ibyte_prefetch(int32_t o)
138 uint32_t currpc = m68k_getpc();
139 uint32_t addr = currpc + o + 1;
140 uint32_t offs = addr - regs.prefetch_pc;
144 refill_prefetch(currpc, o + 1);
145 offs = addr - regs.prefetch_pc;
148 uint32_t v = do_get_mem_byte(((uint8_t *)®s.prefetch) + offs);
151 refill_prefetch(currpc, 2);
153 /* printf ("get_ibyte PC %lx ADDR %lx OFFS %lx V %lx\n", currpc, addr, offs, v); */
160 STATIC_INLINE uint32_t get_iword_prefetch(int32_t o)
163 uint32_t currpc = m68k_getpc();
164 uint32_t addr = currpc + o;
165 uint32_t offs = addr - regs.prefetch_pc;
169 refill_prefetch(currpc, o);
170 offs = addr - regs.prefetch_pc;
173 uint32_t v = do_get_mem_word(((uint8_t *)®s.prefetch) + offs);
176 refill_prefetch(currpc, 2);
178 /* printf ("get_iword PC %lx ADDR %lx OFFS %lx V %lx\n", currpc, addr, offs, v); */
185 STATIC_INLINE uint32_t get_ilong_prefetch(int32_t o)
188 uint32_t v = get_iword_prefetch(o);
190 v |= get_iword_prefetch(o + 2);
197 STATIC_INLINE void fill_prefetch_0(void)
201 #define fill_prefetch_2 fill_prefetch_0
203 #endif // __INLINES_H__