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 |
30 |
R->S = SvIV( get_sv("M6502::S", FALSE) ); |
R->S = SvIV( get_sv("M6502::S", FALSE) ); |
31 |
R->PC.W = SvIV( get_sv("M6502::PC", FALSE) ); |
R->PC.W = SvIV( get_sv("M6502::PC", FALSE) ); |
32 |
R->IPeriod = SvIV( get_sv("M6502::IPeriod", FALSE) ); |
R->IPeriod = SvIV( get_sv("M6502::IPeriod", FALSE) ); |
33 |
// ICount IRequest IAutoReset TrapBadOps Trap Trace |
R->IRequest = SvIV( get_sv("M6502::IRequest", FALSE) ); |
34 |
|
R->IAutoReset = SvIV( get_sv("M6502::IAutoReset", FALSE) ); |
35 |
|
R->TrapBadOps = SvIV( get_sv("M6502::TrapBadOps", FALSE) ); |
36 |
|
R->Trap = SvIV( get_sv("M6502::Trap", FALSE) ); |
37 |
|
R->Trace = SvIV( get_sv("M6502::Trace", FALSE) ); |
38 |
printf("pull_R finished\n"); |
printf("pull_R finished\n"); |
39 |
dump_R; |
dump_R; |
40 |
} |
} |
50 |
XPUSHs( sv_2mortal( newSViv( R->Y ) ) ); |
XPUSHs( sv_2mortal( newSViv( R->Y ) ) ); |
51 |
XPUSHs( sv_2mortal( newSViv( R->S ) ) ); |
XPUSHs( sv_2mortal( newSViv( R->S ) ) ); |
52 |
XPUSHs( sv_2mortal( newSViv( R->PC.W ) ) ); |
XPUSHs( sv_2mortal( newSViv( R->PC.W ) ) ); |
53 |
|
XPUSHs( sv_2mortal( newSViv( R->IPeriod ) ) ); |
54 |
|
XPUSHs( sv_2mortal( newSViv( R->ICount ) ) ); |
55 |
|
XPUSHs( sv_2mortal( newSViv( R->IRequest ) ) ); |
56 |
|
XPUSHs( sv_2mortal( newSViv( R->IAutoReset ) ) ); |
57 |
|
XPUSHs( sv_2mortal( newSViv( R->TrapBadOps ) ) ); |
58 |
|
XPUSHs( sv_2mortal( newSViv( R->Trap ) ) ); |
59 |
|
XPUSHs( sv_2mortal( newSViv( R->Trace ) ) ); |
60 |
PUTBACK; |
PUTBACK; |
61 |
call_pv("M6502::push_R", G_DISCARD ); |
call_pv("M6502::push_R", G_DISCARD ); |
62 |
printf("push_R called\n"); |
printf("push_R called\n"); |
133 |
/** INT_NONE, INT_IRQ, INT_NMI, or INT_QUIT to exit the **/ |
/** INT_NONE, INT_IRQ, INT_NMI, or INT_QUIT to exit the **/ |
134 |
/** emulation loop. **/ |
/** emulation loop. **/ |
135 |
/************************************ TO BE WRITTEN BY USER **/ |
/************************************ TO BE WRITTEN BY USER **/ |
136 |
|
|
137 |
|
int hw_int = INT_NONE; |
138 |
|
|
139 |
byte Loop6502(register M6502 *R) { |
byte Loop6502(register M6502 *R) { |
140 |
debugf(("Loop6502\n")); |
debugf(("Loop6502\n")); |
141 |
dump_R; |
dump_R; |
142 |
return INT_NONE; |
return hw_int; |
143 |
} |
} |
144 |
|
|
145 |
/** Patch6502() **********************************************/ |
/** Patch6502() **********************************************/ |
152 |
byte Patch6502(register byte Op,register M6502 *R) { |
byte Patch6502(register byte Op,register M6502 *R) { |
153 |
debugf(("Patch6502(%02x)\n", Op)); |
debugf(("Patch6502(%02x)\n", Op)); |
154 |
dump_R; |
dump_R; |
155 |
|
hw_int = INT_QUIT; |
156 |
return 0; |
return 0; |
157 |
} |
} |
158 |
|
|
159 |
|
void run_forever(void) { |
160 |
|
printf("entered run_forever\n"); |
161 |
|
|
162 |
|
R = malloc(sizeof(M6502)); |
163 |
|
if (!R) { |
164 |
|
printf("can't alloc %d bytes for M6502", sizeof(M6502)); |
165 |
|
exit(1); |
166 |
|
} |
167 |
|
|
168 |
|
printf("reset CPU\n"); |
169 |
|
Reset6502(R); |
170 |
|
|
171 |
|
printf("call Arch::init\n"); |
172 |
|
dSP; |
173 |
|
PUSHMARK(SP); |
174 |
|
call_pv("Arch::init", G_DISCARD | G_NOARGS ); |
175 |
|
FREETMPS; |
176 |
|
LEAVE; |
177 |
|
|
178 |
|
int cycles = 1; |
179 |
|
while ( cycles ) { |
180 |
|
dSP; |
181 |
|
PUSHMARK(SP); |
182 |
|
call_pv("Arch::cli", G_DISCARD | G_NOARGS ); |
183 |
|
pull_R(R); |
184 |
|
FREETMPS; |
185 |
|
LEAVE; |
186 |
|
cycles = SvIV( get_sv("M6502::run_for", FALSE) ); |
187 |
|
if ( cycles > 0 ) { |
188 |
|
printf("run CPU for %d cycles\n", cycles); |
189 |
|
dump_R; |
190 |
|
//Run6502(R); |
191 |
|
Exec6502(R, cycles); |
192 |
|
dump_R; |
193 |
|
push_R(R); |
194 |
|
printf("end of %d cycles CPU run\n", cycles); |
195 |
|
} else { |
196 |
|
printf("no cpu cycles set for run\n"); |
197 |
|
cycles = 1; // never exit, prevents segfault |
198 |
|
} |
199 |
|
} |
200 |
|
free(R); |
201 |
|
} |
202 |
|
|
203 |
/** |
/** |
204 |
* main code |
* main code |
205 |
* |
* |
218 |
printf("Failed to execute\n"); |
printf("Failed to execute\n"); |
219 |
return 0; |
return 0; |
220 |
} else { |
} else { |
221 |
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 ); |
|
|
|
|
|
pull_R(R); |
|
|
int 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 CPU run\n"); |
|
222 |
} |
} |
|
free(R); |
|
223 |
perl_destruct(my_perl); |
perl_destruct(my_perl); |
224 |
perl_free(my_perl); |
perl_free(my_perl); |
225 |
return 0; |
return 0; |