]> Shamusworld >> Repos - virtualjaguar/blob - src/m68000/inlines.h
3dee46f315e4150d90739a6525d1dfcde1f6206e
[virtualjaguar] / src / m68000 / inlines.h
1 //
2 // Inline functions used by cpuemu.c
3 //
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.
6 //
7
8 #ifndef __INLINES_H__
9 #define __INLINES_H__
10
11 #include "cpudefs.h"
12
13 STATIC_INLINE int cctrue(const int cc)
14 {
15         switch (cc)
16         {
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 */
33         }
34
35         abort();
36         return 0;
37 }
38
39 //no #define m68k_incpc(o) (regs.pc_p += (o))
40 #define m68k_incpc(o) (regs.pc += (o))
41
42 STATIC_INLINE void m68k_setpc(uint32_t newpc)
43 {
44         //This is only done here... (get_real_address())
45 //      regs.pc_p = regs.pc_oldp = get_real_address(newpc);
46         regs.pc = newpc;
47 }
48
49 #define m68k_setpc_rte  m68k_setpc
50
51 STATIC_INLINE uint32_t m68k_getpc(void)
52 {
53 //      return regs.pc + ((char *)regs.pc_p - (char *)regs.pc_oldp);
54         return regs.pc;
55 }
56
57 #if 0
58 STATIC_INLINE uint32_t m68k_getpc_p(uint8_t * p)
59 {
60         return regs.pc + ((char *)p - (char *)regs.pc_oldp);
61 }
62 #endif
63
64 STATIC_INLINE void m68k_setstopped(int stop)
65 {
66         regs.stopped = stop;
67         regs.remainingCycles = 0;
68
69 //But trace instructions are only on >68000 cpus, so this is bogus.
70 #if 0
71         /* A traced STOP instruction drops through immediately without
72         actually stopping.  */
73         if (stop && (regs.spcflags & SPCFLAG_DOTRACE) == 0)
74         regs.spcflags |= SPCFLAG_STOP;
75 #endif
76 }
77
78 STATIC_INLINE void m68k_do_rts(void)
79 {
80         m68k_setpc(m68k_read_memory_32(m68k_areg(regs, 7)));
81         m68k_areg(regs, 7) += 4;
82 }
83
84 STATIC_INLINE void m68k_do_bsr(uint32_t oldpc, int32_t offset)
85 {
86         m68k_areg(regs, 7) -= 4;
87         m68k_write_memory_32(m68k_areg(regs, 7), oldpc);
88         m68k_incpc(offset);
89 }
90
91 STATIC_INLINE void m68k_do_jsr(uint32_t oldpc, uint32_t dest)
92 {
93         m68k_areg(regs, 7) -= 4;
94         m68k_write_memory_32(m68k_areg(regs, 7), oldpc);
95         m68k_setpc(dest);
96 }
97
98 #if 0
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))
106 #else
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))
112 #endif
113
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)
116 {
117 #if 0
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;
121         uint32_t r;
122
123 #ifdef UNALIGNED_PROFITABLE
124         r = *(uint32_t *)ptr;
125         regs.prefetch = r;
126 #else
127         r = do_get_mem_long(ptr);
128         do_put_mem_long(&regs.prefetch, r);
129 #endif
130         /* printf ("PC %lx T %lx PCPOFFS %d R %lx\n", currpc, t, pc_p_offs, r); */
131         regs.prefetch_pc = t;
132 #endif
133 }
134
135 STATIC_INLINE uint32_t get_ibyte_prefetch(int32_t o)
136 {
137 #if 0
138         uint32_t currpc = m68k_getpc();
139         uint32_t addr = currpc + o + 1;
140         uint32_t offs = addr - regs.prefetch_pc;
141
142         if (offs > 3)
143         {
144                 refill_prefetch(currpc, o + 1);
145                 offs = addr - regs.prefetch_pc;
146         }
147
148         uint32_t v = do_get_mem_byte(((uint8_t *)&regs.prefetch) + offs);
149
150         if (offs >= 2)
151                 refill_prefetch(currpc, 2);
152
153         /* printf ("get_ibyte PC %lx ADDR %lx OFFS %lx V %lx\n", currpc, addr, offs, v); */
154         return v;
155 #else
156         return get_ibyte(o);
157 #endif
158 }
159
160 STATIC_INLINE uint32_t get_iword_prefetch(int32_t o)
161 {
162 #if 0
163         uint32_t currpc = m68k_getpc();
164         uint32_t addr = currpc + o;
165         uint32_t offs = addr - regs.prefetch_pc;
166
167         if (offs > 3)
168         {
169                 refill_prefetch(currpc, o);
170                 offs = addr - regs.prefetch_pc;
171         }
172
173         uint32_t v = do_get_mem_word(((uint8_t *)&regs.prefetch) + offs);
174
175         if (offs >= 2)
176                 refill_prefetch(currpc, 2);
177
178 /*      printf ("get_iword PC %lx ADDR %lx OFFS %lx V %lx\n", currpc, addr, offs, v); */
179         return v;
180 #else
181         return get_iword(o);
182 #endif
183 }
184
185 STATIC_INLINE uint32_t get_ilong_prefetch(int32_t o)
186 {
187 #if 0
188         uint32_t v = get_iword_prefetch(o);
189         v <<= 16;
190         v |= get_iword_prefetch(o + 2);
191         return v;
192 #else
193         return get_ilong(o);
194 #endif
195 }
196
197 STATIC_INLINE void fill_prefetch_0(void)
198 {
199 }
200
201 #define fill_prefetch_2 fill_prefetch_0
202
203 #endif  // __INLINES_H__