10 |
M6502 *R = NULL; |
M6502 *R = NULL; |
11 |
int debug = 0; |
int debug = 0; |
12 |
|
|
13 |
|
// same as memory size |
14 |
|
#define CACHE_SIZE 0xffff |
15 |
byte opCache[CACHE_SIZE]; |
byte opCache[CACHE_SIZE]; |
16 |
|
|
17 |
|
#define CALLBACK_READ_SKIP 0x00 |
18 |
|
#define CALLBACK_READ_ONCE 0x01 |
19 |
|
#define CALLBACK_READ_ALWAYS 0x02 |
20 |
|
#define CALLBACK_READ_MASK 0x0f |
21 |
|
#define CALLBACK_WRITE_SKIP 0x00 |
22 |
|
#define CALLBACK_WRITE_ONCE 0x10 |
23 |
|
#define CALLBACK_WRITE_ALWAYS 0x20 |
24 |
|
#define CALLBACK_WRITE_MASK 0xf0 |
25 |
|
byte perlCallBack[CACHE_SIZE]; |
26 |
|
|
27 |
void update_C_R(void) { |
void update_C_R(void) { |
28 |
R->A = SvIV( get_sv("M6502::A", FALSE) ); |
R->A = SvIV( get_sv("M6502::A", FALSE) ); |
29 |
R->P = SvIV( get_sv("M6502::P", FALSE) ); |
R->P = SvIV( get_sv("M6502::P", FALSE) ); |
83 |
/** required if there is a #define FAST_RDOP. **/ |
/** required if there is a #define FAST_RDOP. **/ |
84 |
/************************************ TO BE WRITTEN BY USER **/ |
/************************************ TO BE WRITTEN BY USER **/ |
85 |
|
|
86 |
byte mem(word Addr) { |
byte mem(register word Addr) { |
87 |
|
|
88 |
|
if ( perlCallBack[Addr] & CALLBACK_READ_MASK == CALLBACK_READ_SKIP ) |
89 |
|
return opCache[Addr]; |
90 |
|
if ( perlCallBack[Addr] & CALLBACK_READ_MASK == CALLBACK_READ_ONCE ) |
91 |
|
perlCallBack[Addr] = perlCallBack[Addr] & CALLBACK_WRITE_MASK | CALLBACK_READ_SKIP; |
92 |
|
|
93 |
byte byte; |
byte byte; |
94 |
int count; |
int count; |
95 |
debugf(("mem(%04x)", Addr)); |
debugf(("mem(%04x)", Addr)); |
130 |
void Wr6502(register word Addr,register byte Value) { |
void Wr6502(register word Addr,register byte Value) { |
131 |
debugf(("Wr6502(%04x,%02x)", Addr, Value)); |
debugf(("Wr6502(%04x,%02x)", Addr, Value)); |
132 |
opCache[Addr] = Value; |
opCache[Addr] = Value; |
133 |
|
if ( perlCallBack[Addr] & CALLBACK_WRITE_MASK == CALLBACK_WRITE_SKIP ) return; |
134 |
|
if ( perlCallBack[Addr] & CALLBACK_WRITE_MASK == CALLBACK_WRITE_ONCE ) |
135 |
|
perlCallBack[Addr] = perlCallBack[Addr] & CALLBACK_READ_MASK | CALLBACK_WRITE_SKIP; |
136 |
dSP; |
dSP; |
137 |
ENTER; |
ENTER; |
138 |
SAVETMPS; |
SAVETMPS; |
147 |
|
|
148 |
byte Op6502(register word Addr) { |
byte Op6502(register word Addr) { |
149 |
byte Op; |
byte Op; |
|
if ( opCache[Addr] ) return opCache[Addr]; |
|
150 |
Op = mem(Addr); |
Op = mem(Addr); |
151 |
debugf(("Op6502(%04x,%02x) PC:%04x", Addr, Op, R->PC.W)); |
debugf(("Op6502(%04x,%02x) PC:%04x", Addr, Op, R->PC.W)); |
152 |
return Op; |
return Op; |
194 |
PerlIO_stdoutf("can't alloc %d bytes for M6502", sizeof(M6502)); |
PerlIO_stdoutf("can't alloc %d bytes for M6502", sizeof(M6502)); |
195 |
exit(1); |
exit(1); |
196 |
} |
} |
197 |
memset( opCache, 0, sizeof(opCache) ); |
memset( opCache, 0, CACHE_SIZE ); |
198 |
|
memset( perlCallBack, CALLBACK_READ_ALWAYS | CALLBACK_WRITE_ALWAYS, CACHE_SIZE ); |
199 |
} |
} |
200 |
Reset6502(R); |
Reset6502(R); |
201 |
debugf(("Reset6502 over")); |
debugf(("Reset6502 over")); |
226 |
return debug; |
return debug; |
227 |
} |
} |
228 |
|
|
229 |
|
/* FIXME somehow check if Addr will fit in int on current platform */ |
230 |
|
void set_read_callback(int Addr) { |
231 |
|
perlCallBack[Addr] == perlCallBack[Addr] & CALLBACK_WRITE_MASK | CALLBACK_READ_ALWAYS; |
232 |
|
} |
233 |
|
|
234 |
|
void set_write_callback(int Addr) { |
235 |
|
perlCallBack[Addr] == perlCallBack[Addr] & CALLBACK_READ_MASK | CALLBACK_WRITE_ALWAYS; |
236 |
|
} |
237 |
|
|
238 |
|
/* we fake here, since we will need to call perl at least once to get initial value... */ |
239 |
|
int disable_all_callbacks(void) { |
240 |
|
memset( perlCallBack, CALLBACK_READ_ONCE | CALLBACK_WRITE_ONCE, CACHE_SIZE ); |
241 |
|
return perlCallBack[0]; |
242 |
|
} |
243 |
|
|
244 |
|
|
245 |
MODULE = M6502 PACKAGE = M6502 |
MODULE = M6502 PACKAGE = M6502 |
246 |
|
|
247 |
PROTOTYPES: DISABLE |
PROTOTYPES: DISABLE |
263 |
|
|
264 |
int |
int |
265 |
exec(int cycles) |
exec(int cycles) |
266 |
|
|
267 |
|
void |
268 |
|
set_read_callback(int Addr) |
269 |
|
|
270 |
|
void |
271 |
|
set_write_callback(int Addr) |
272 |
|
|
273 |
|
int |
274 |
|
disable_all_callbacks() |
275 |
|
|