--- M6502/perl.c 2007/07/30 21:34:30 34 +++ M6502/perl.c 2007/07/31 08:41:06 40 @@ -21,19 +21,38 @@ #define dump_R #endif -void update_R(M6502 *R) { +void pull_R(M6502 *R) { R->A = SvIV( get_sv("M6502::A", FALSE) ); - printf("--%d", get_sv("M6502::A", FALSE) ); R->P = SvIV( get_sv("M6502::P", FALSE) ); - R->X = atoi( SvPV_nolen( get_sv("M6502::X", FALSE) ) ); - R->Y = atoi( SvPV_nolen( get_sv("M6502::Y", FALSE) ) ); - R->S = atoi( SvPV_nolen( get_sv("M6502::S", FALSE) ) ); - R->PC.W = atoi( SvPV_nolen( get_sv("M6502::PC", FALSE) ) ); - R->IPeriod = atoi( SvPV_nolen( get_sv("M6502::IPeriod", FALSE) ) ); + R->X = SvIV( get_sv("M6502::X", FALSE) ); + R->Y = SvIV( get_sv("M6502::Y", FALSE) ); + R->S = SvIV( get_sv("M6502::S", FALSE) ); + R->PC.W = SvIV( get_sv("M6502::PC", FALSE) ); + R->IPeriod = SvIV( get_sv("M6502::IPeriod", FALSE) ); // ICount IRequest IAutoReset TrapBadOps Trap Trace + printf("pull_R finished\n"); dump_R; } +void push_R(M6502 *R) { + dSP; + ENTER; + SAVETMPS; + PUSHMARK(SP); + XPUSHs( sv_2mortal( newSViv( R->A ) ) ); + XPUSHs( sv_2mortal( newSViv( R->P ) ) ); + XPUSHs( sv_2mortal( newSViv( R->X ) ) ); + XPUSHs( sv_2mortal( newSViv( R->Y ) ) ); + XPUSHs( sv_2mortal( newSViv( R->S ) ) ); + XPUSHs( sv_2mortal( newSViv( R->PC.W ) ) ); + PUTBACK; + call_pv("M6502::push_R", G_DISCARD ); + printf("push_R called\n"); + dump_R; + FREETMPS; + LEAVE; +} + /** Rd6502()/Wr6502/Op6502() *********************************/ /** These functions are called when access to RAM occurs. **/ /** They allow to control memory access. Op6502 is the same **/ @@ -91,8 +110,8 @@ byte Op6502(register word Addr) { byte Op; Op = mem(Addr); - debugf(("Op6502(%04x,%02x)\n", Addr, Op)); - dump_R; + debugf(("Op6502(%04x,%02x) PC:%04x\n", Addr, Op, R->PC.W)); + return Op; } /** Loop6502() ***********************************************/ @@ -153,10 +172,15 @@ PUSHMARK(SP); call_pv("Arch::init", G_DISCARD | G_NOARGS ); - update_R(R); - printf("run CPU\n"); - Run6502(R); - + 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"); } free(R); perl_destruct(my_perl);