5 |
|
|
6 |
#if DEBUGF |
#if DEBUGF |
7 |
#define debugf(x) do { \ |
#define debugf(x) do { \ |
8 |
|
PerlIO_stdoutf("#> "); \ |
9 |
PerlIO_stdoutf x ; \ |
PerlIO_stdoutf x ; \ |
10 |
} while (0) |
} while (0) |
11 |
#else |
#else |
22 |
#define dump_R |
#define dump_R |
23 |
#endif |
#endif |
24 |
|
|
25 |
void update_R(M6502 *R) { |
void pull_R(M6502 *R) { |
26 |
R->A = SvIV( get_sv("M6502::A", FALSE) ); |
R->A = SvIV( get_sv("M6502::A", FALSE) ); |
|
printf("--%d", get_sv("M6502::A", FALSE) ); |
|
27 |
R->P = SvIV( get_sv("M6502::P", FALSE) ); |
R->P = SvIV( get_sv("M6502::P", FALSE) ); |
28 |
R->X = atoi( SvPV_nolen( get_sv("M6502::X", FALSE) ) ); |
R->X = SvIV( get_sv("M6502::X", FALSE) ); |
29 |
R->Y = atoi( SvPV_nolen( get_sv("M6502::Y", FALSE) ) ); |
R->Y = SvIV( get_sv("M6502::Y", FALSE) ); |
30 |
R->S = atoi( SvPV_nolen( get_sv("M6502::S", FALSE) ) ); |
R->S = SvIV( get_sv("M6502::S", FALSE) ); |
31 |
R->PC.W = atoi( SvPV_nolen( get_sv("M6502::PC", FALSE) ) ); |
R->PC.W = SvIV( get_sv("M6502::PC", FALSE) ); |
32 |
R->IPeriod = atoi( SvPV_nolen( get_sv("M6502::IPeriod", FALSE) ) ); |
R->IPeriod = SvIV( get_sv("M6502::IPeriod", FALSE) ); |
33 |
// ICount IRequest IAutoReset TrapBadOps Trap Trace |
// ICount IRequest IAutoReset TrapBadOps Trap Trace |
34 |
|
printf("pull_R finished\n"); |
35 |
dump_R; |
dump_R; |
36 |
} |
} |
37 |
|
|
38 |
|
void push_R(M6502 *R) { |
39 |
|
dSP; |
40 |
|
ENTER; |
41 |
|
SAVETMPS; |
42 |
|
PUSHMARK(SP); |
43 |
|
XPUSHs( sv_2mortal( newSViv( R->A ) ) ); |
44 |
|
XPUSHs( sv_2mortal( newSViv( R->P ) ) ); |
45 |
|
XPUSHs( sv_2mortal( newSViv( R->X ) ) ); |
46 |
|
XPUSHs( sv_2mortal( newSViv( R->Y ) ) ); |
47 |
|
XPUSHs( sv_2mortal( newSViv( R->S ) ) ); |
48 |
|
XPUSHs( sv_2mortal( newSViv( R->PC.W ) ) ); |
49 |
|
PUTBACK; |
50 |
|
call_pv("M6502::push_R", G_DISCARD ); |
51 |
|
printf("push_R called\n"); |
52 |
|
dump_R; |
53 |
|
FREETMPS; |
54 |
|
LEAVE; |
55 |
|
} |
56 |
|
|
57 |
/** Rd6502()/Wr6502/Op6502() *********************************/ |
/** Rd6502()/Wr6502/Op6502() *********************************/ |
58 |
/** These functions are called when access to RAM occurs. **/ |
/** These functions are called when access to RAM occurs. **/ |
59 |
/** They allow to control memory access. Op6502 is the same **/ |
/** They allow to control memory access. Op6502 is the same **/ |
111 |
byte Op6502(register word Addr) { |
byte Op6502(register word Addr) { |
112 |
byte Op; |
byte Op; |
113 |
Op = mem(Addr); |
Op = mem(Addr); |
114 |
debugf(("Op6502(%04x,%02x)\n", Addr, Op)); |
debugf(("Op6502(%04x,%02x) PC:%04x\n", Addr, Op, R->PC.W)); |
115 |
dump_R; |
return Op; |
116 |
} |
} |
117 |
|
|
118 |
/** Loop6502() ***********************************************/ |
/** Loop6502() ***********************************************/ |
122 |
/** INT_NONE, INT_IRQ, INT_NMI, or INT_QUIT to exit the **/ |
/** INT_NONE, INT_IRQ, INT_NMI, or INT_QUIT to exit the **/ |
123 |
/** emulation loop. **/ |
/** emulation loop. **/ |
124 |
/************************************ TO BE WRITTEN BY USER **/ |
/************************************ TO BE WRITTEN BY USER **/ |
125 |
|
|
126 |
|
int hw_int = INT_NONE; |
127 |
|
|
128 |
byte Loop6502(register M6502 *R) { |
byte Loop6502(register M6502 *R) { |
129 |
debugf(("Loop6502\n")); |
debugf(("Loop6502\n")); |
130 |
dump_R; |
dump_R; |
131 |
return INT_NONE; |
return hw_int; |
132 |
} |
} |
133 |
|
|
134 |
/** Patch6502() **********************************************/ |
/** Patch6502() **********************************************/ |
176 |
PUSHMARK(SP); |
PUSHMARK(SP); |
177 |
call_pv("Arch::init", G_DISCARD | G_NOARGS ); |
call_pv("Arch::init", G_DISCARD | G_NOARGS ); |
178 |
|
|
179 |
update_R(R); |
int cycles = 1; |
180 |
printf("run CPU\n"); |
while ( cycles ) { |
181 |
Run6502(R); |
call_pv("Arch::cli", G_DISCARD | G_NOARGS ); |
182 |
|
pull_R(R); |
183 |
|
cycles = SvIV( get_sv("M6502::run_for", FALSE) ); |
184 |
|
printf("run CPU for %d cycles\n", cycles); |
185 |
|
dump_R; |
186 |
|
//Run6502(R); |
187 |
|
Exec6502(R, cycles); |
188 |
|
dump_R; |
189 |
|
push_R(R); |
190 |
|
printf("end of %d cycles CPU run\n", cycles); |
191 |
|
} |
192 |
} |
} |
193 |
free(R); |
free(R); |
194 |
perl_destruct(my_perl); |
perl_destruct(my_perl); |