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]; |
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 |
|
debugf(("mem(%04x) callback %02x", Addr, perlCallBack[Addr])); |
88 |
|
|
89 |
|
debugf(("### SKIP? %02x == %02x", perlCallBack[Addr] & CALLBACK_READ_MASK, CALLBACK_READ_SKIP)); |
90 |
|
if ( ( perlCallBack[Addr] & CALLBACK_READ_MASK ) == CALLBACK_READ_SKIP ) { |
91 |
|
debugf(("MEM: read callback skipped")); |
92 |
|
return opCache[Addr]; |
93 |
|
} |
94 |
|
if ( ( perlCallBack[Addr] & CALLBACK_READ_MASK ) == CALLBACK_READ_ONCE ) { |
95 |
|
debugf(("MEM: read callback disabled")); |
96 |
|
perlCallBack[Addr] = perlCallBack[Addr] & CALLBACK_WRITE_MASK | CALLBACK_READ_SKIP; |
97 |
|
} |
98 |
|
|
99 |
byte byte; |
byte byte; |
100 |
int count; |
int count; |
|
debugf(("mem(%04x)", Addr)); |
|
101 |
dSP; |
dSP; |
102 |
ENTER; |
ENTER; |
103 |
SAVETMPS; |
SAVETMPS; |
121 |
FREETMPS; |
FREETMPS; |
122 |
LEAVE; |
LEAVE; |
123 |
debugf(("mem(%04x) = %02x", Addr, byte)); |
debugf(("mem(%04x) = %02x", Addr, byte)); |
124 |
|
opCache[Addr] = byte; |
125 |
return byte; |
return byte; |
126 |
} |
} |
127 |
|
|
128 |
byte Rd6502(register word Addr) { |
byte Rd6502(register word Addr) { |
129 |
byte Value; |
byte Value; |
130 |
Value = mem(Addr); |
Value = mem(Addr); |
|
// Value = 0x42; |
|
131 |
debugf(("Rd6502(%04x) = %02x", Addr, Value)); |
debugf(("Rd6502(%04x) = %02x", Addr, Value)); |
132 |
return Value; |
return Value; |
133 |
} |
} |
134 |
|
|
135 |
void Wr6502(register word Addr,register byte Value) { |
void Wr6502(register word Addr,register byte Value) { |
136 |
debugf(("Wr6502(%04x,%02x)", Addr, Value)); |
debugf(("Wr6502(%04x,%02x)", Addr, Value)); |
137 |
|
opCache[Addr] = Value; |
138 |
|
if ( ( perlCallBack[Addr] & CALLBACK_WRITE_MASK ) == CALLBACK_WRITE_SKIP ) { |
139 |
|
debugf(("MEM: write callback skipped")); |
140 |
|
return; |
141 |
|
} |
142 |
|
if ( ( perlCallBack[Addr] & CALLBACK_WRITE_MASK ) == CALLBACK_WRITE_ONCE ) { |
143 |
|
perlCallBack[Addr] = perlCallBack[Addr] & CALLBACK_READ_MASK | CALLBACK_WRITE_SKIP; |
144 |
|
debugf(("MEM: write callback skipped")); |
145 |
|
} |
146 |
dSP; |
dSP; |
147 |
ENTER; |
ENTER; |
148 |
SAVETMPS; |
SAVETMPS; |
204 |
PerlIO_stdoutf("can't alloc %d bytes for M6502", sizeof(M6502)); |
PerlIO_stdoutf("can't alloc %d bytes for M6502", sizeof(M6502)); |
205 |
exit(1); |
exit(1); |
206 |
} |
} |
207 |
|
memset( opCache, 0, CACHE_SIZE ); |
208 |
|
memset( perlCallBack, CALLBACK_READ_ALWAYS | CALLBACK_WRITE_ALWAYS, CACHE_SIZE ); |
209 |
} |
} |
210 |
Reset6502(R); |
Reset6502(R); |
211 |
debugf(("Reset6502 over")); |
debugf(("Reset6502 over")); |
236 |
return debug; |
return debug; |
237 |
} |
} |
238 |
|
|
239 |
|
/* FIXME somehow check if Addr will fit in int on current platform */ |
240 |
|
void set_read_callback(int Addr) { |
241 |
|
perlCallBack[Addr] == perlCallBack[Addr] & CALLBACK_WRITE_MASK | CALLBACK_READ_ALWAYS; |
242 |
|
debugf(("MEM: %04x read callback\n", Addr)); |
243 |
|
} |
244 |
|
|
245 |
|
void set_write_callback(int Addr) { |
246 |
|
perlCallBack[Addr] == perlCallBack[Addr] & CALLBACK_READ_MASK | CALLBACK_WRITE_ALWAYS; |
247 |
|
debugf(("MEM: %04x write callback\n", Addr)); |
248 |
|
} |
249 |
|
|
250 |
|
/* we fake here, since we will need to call perl at least once to get initial value... */ |
251 |
|
int set_all_callbacks(int mode) { |
252 |
|
memset( perlCallBack, mode, CACHE_SIZE ); |
253 |
|
debugf(("MEM: all callbacks set to %02x\n", perlCallBack[0])); |
254 |
|
return perlCallBack[0]; |
255 |
|
} |
256 |
|
|
257 |
|
int get_callback(int Addr) { |
258 |
|
return perlCallBack[Addr]; |
259 |
|
} |
260 |
|
|
261 |
|
|
262 |
MODULE = M6502 PACKAGE = M6502 |
MODULE = M6502 PACKAGE = M6502 |
263 |
|
|
264 |
PROTOTYPES: DISABLE |
PROTOTYPES: DISABLE |
280 |
|
|
281 |
int |
int |
282 |
exec(int cycles) |
exec(int cycles) |
283 |
|
|
284 |
|
void |
285 |
|
set_read_callback(int Addr) |
286 |
|
|
287 |
|
void |
288 |
|
set_write_callback(int Addr) |
289 |
|
|
290 |
|
int |
291 |
|
set_all_callbacks(int mode) |
292 |
|
|
293 |
|
int get_callback(int Addr) |