3 |
#include "M6502.h" |
#include "M6502.h" |
4 |
#include "config.h" |
#include "config.h" |
5 |
|
|
|
#if DEBUGF |
|
|
#define debugf(x) do { \ |
|
|
PerlIO_stdoutf("#> "); \ |
|
|
PerlIO_stdoutf x ; \ |
|
|
} while (0) |
|
|
#else |
|
|
#define debugf(x) |
|
|
#endif |
|
|
|
|
6 |
static PerlInterpreter *my_perl; |
static PerlInterpreter *my_perl; |
7 |
|
|
8 |
static M6502 *R; |
static M6502 *R; |
21 |
R->S = SvIV( get_sv("M6502::S", FALSE) ); |
R->S = SvIV( get_sv("M6502::S", FALSE) ); |
22 |
R->PC.W = SvIV( get_sv("M6502::PC", FALSE) ); |
R->PC.W = SvIV( get_sv("M6502::PC", FALSE) ); |
23 |
R->IPeriod = SvIV( get_sv("M6502::IPeriod", FALSE) ); |
R->IPeriod = SvIV( get_sv("M6502::IPeriod", FALSE) ); |
24 |
// ICount IRequest IAutoReset TrapBadOps Trap Trace |
R->IRequest = SvIV( get_sv("M6502::IRequest", FALSE) ); |
25 |
|
R->IAutoReset = SvIV( get_sv("M6502::IAutoReset", FALSE) ); |
26 |
|
R->TrapBadOps = SvIV( get_sv("M6502::TrapBadOps", FALSE) ); |
27 |
|
R->Trap = SvIV( get_sv("M6502::Trap", FALSE) ); |
28 |
|
R->Trace = SvIV( get_sv("M6502::Trace", FALSE) ); |
29 |
printf("pull_R finished\n"); |
printf("pull_R finished\n"); |
30 |
dump_R; |
dump_R; |
31 |
} |
} |
41 |
XPUSHs( sv_2mortal( newSViv( R->Y ) ) ); |
XPUSHs( sv_2mortal( newSViv( R->Y ) ) ); |
42 |
XPUSHs( sv_2mortal( newSViv( R->S ) ) ); |
XPUSHs( sv_2mortal( newSViv( R->S ) ) ); |
43 |
XPUSHs( sv_2mortal( newSViv( R->PC.W ) ) ); |
XPUSHs( sv_2mortal( newSViv( R->PC.W ) ) ); |
44 |
|
XPUSHs( sv_2mortal( newSViv( R->IPeriod ) ) ); |
45 |
|
XPUSHs( sv_2mortal( newSViv( R->ICount ) ) ); |
46 |
|
XPUSHs( sv_2mortal( newSViv( R->IRequest ) ) ); |
47 |
|
XPUSHs( sv_2mortal( newSViv( R->IAutoReset ) ) ); |
48 |
|
XPUSHs( sv_2mortal( newSViv( R->TrapBadOps ) ) ); |
49 |
|
XPUSHs( sv_2mortal( newSViv( R->Trap ) ) ); |
50 |
|
XPUSHs( sv_2mortal( newSViv( R->Trace ) ) ); |
51 |
PUTBACK; |
PUTBACK; |
52 |
call_pv("M6502::push_R", G_DISCARD ); |
call_pv("M6502::push_R", G_DISCARD ); |
53 |
printf("push_R called\n"); |
printf("push_R called\n"); |
56 |
LEAVE; |
LEAVE; |
57 |
} |
} |
58 |
|
|
59 |
|
byte Debug6502(M6502 *R) { |
60 |
|
dump_R; |
61 |
|
return 1; // continue emulation |
62 |
|
} |
63 |
|
|
64 |
/** Rd6502()/Wr6502/Op6502() *********************************/ |
/** Rd6502()/Wr6502/Op6502() *********************************/ |
65 |
/** These functions are called when access to RAM occurs. **/ |
/** These functions are called when access to RAM occurs. **/ |
66 |
/** They allow to control memory access. Op6502 is the same **/ |
/** They allow to control memory access. Op6502 is the same **/ |
72 |
byte mem(word Addr) { |
byte mem(word Addr) { |
73 |
byte byte; |
byte byte; |
74 |
int count; |
int count; |
75 |
|
debugf(("mem(%04x)\n", Addr)); |
76 |
dSP; |
dSP; |
77 |
ENTER; |
ENTER; |
78 |
SAVETMPS; |
SAVETMPS; |
149 |
byte Patch6502(register byte Op,register M6502 *R) { |
byte Patch6502(register byte Op,register M6502 *R) { |
150 |
debugf(("Patch6502(%02x)\n", Op)); |
debugf(("Patch6502(%02x)\n", Op)); |
151 |
dump_R; |
dump_R; |
152 |
|
hw_int = INT_QUIT; |
153 |
return 0; |
return 0; |
154 |
} |
} |
155 |
|
|
156 |
|
void run_forever(void) { |
157 |
|
printf("entered run_forever\n"); |
158 |
|
|
159 |
|
R = malloc(sizeof(M6502)); |
160 |
|
if (!R) { |
161 |
|
printf("can't alloc %d bytes for M6502", sizeof(M6502)); |
162 |
|
exit(1); |
163 |
|
} |
164 |
|
|
165 |
|
printf("reset CPU\n"); |
166 |
|
Reset6502(R); |
167 |
|
|
168 |
|
printf("call Arch::init\n"); |
169 |
|
dSP; |
170 |
|
PUSHMARK(SP); |
171 |
|
call_pv("Arch::init", G_DISCARD | G_NOARGS ); |
172 |
|
FREETMPS; |
173 |
|
LEAVE; |
174 |
|
|
175 |
|
int cycles = 1; |
176 |
|
while ( cycles ) { |
177 |
|
dSP; |
178 |
|
PUSHMARK(SP); |
179 |
|
call_pv("Arch::cli", G_DISCARD | G_NOARGS ); |
180 |
|
pull_R(R); |
181 |
|
FREETMPS; |
182 |
|
LEAVE; |
183 |
|
cycles = SvIV( get_sv("M6502::run_for", FALSE) ); |
184 |
|
if ( cycles > 0 ) { |
185 |
|
printf("run CPU for %d cycles\n", cycles); |
186 |
|
dump_R; |
187 |
|
//Run6502(R); |
188 |
|
Exec6502(R, cycles); |
189 |
|
dump_R; |
190 |
|
push_R(R); |
191 |
|
printf("end of %d cycles CPU run\n", cycles); |
192 |
|
} else { |
193 |
|
printf("no cpu cycles set for run\n"); |
194 |
|
cycles = 1; // never exit, prevents segfault |
195 |
|
} |
196 |
|
} |
197 |
|
free(R); |
198 |
|
} |
199 |
|
|
200 |
/** |
/** |
201 |
* main code |
* main code |
202 |
* |
* |
215 |
printf("Failed to execute\n"); |
printf("Failed to execute\n"); |
216 |
return 0; |
return 0; |
217 |
} else { |
} else { |
218 |
R = malloc(sizeof(M6502)); |
run_forever(); |
|
if (!R) { |
|
|
printf("can't alloc %d bytes for M6502", sizeof(M6502)); |
|
|
exit(1); |
|
|
} |
|
|
|
|
|
printf("reset CPU\n"); |
|
|
Reset6502(R); |
|
|
|
|
|
printf("call Arch::init\n"); |
|
|
dSP; |
|
|
PUSHMARK(SP); |
|
|
call_pv("Arch::init", G_DISCARD | G_NOARGS ); |
|
|
FREETMPS; |
|
|
LEAVE; |
|
|
|
|
|
int cycles = 1; |
|
|
while ( cycles ) { |
|
|
dSP; |
|
|
PUSHMARK(SP); |
|
|
call_pv("Arch::cli", G_DISCARD | G_NOARGS ); |
|
|
pull_R(R); |
|
|
FREETMPS; |
|
|
LEAVE; |
|
|
cycles = SvIV( get_sv("M6502::run_for", FALSE) ); |
|
|
printf("run CPU for %d cycles\n", cycles); |
|
|
dump_R; |
|
|
//Run6502(R); |
|
|
Exec6502(R, cycles); |
|
|
dump_R; |
|
|
push_R(R); |
|
|
printf("end of %d cycles CPU run\n", cycles); |
|
|
} |
|
219 |
} |
} |
|
free(R); |
|
220 |
perl_destruct(my_perl); |
perl_destruct(my_perl); |
221 |
perl_free(my_perl); |
perl_free(my_perl); |
222 |
return 0; |
return 0; |