--- M6502/perl.c 2007/07/30 21:00:36 33 +++ M6502/perl.c 2007/07/31 08:41:06 40 @@ -3,7 +3,7 @@ #include "M6502.h" #include "config.h" -#ifdef DEBUGF +#if DEBUGF #define debugf(x) do { \ PerlIO_stdoutf x ; \ } while (0) @@ -15,26 +15,44 @@ static M6502 *R; -#if 0 +#if DUMP_R #define dump_R printf("# PC: %04x A:%02x P:%02x X:%02x Y:%02x S:%02x\n", R->PC.W, R->A, R->P, R->X, R->Y, R->S ); #else #define dump_R #endif -void update_R(M6502 *R) { - printf("--0\n"); +void pull_R(M6502 *R) { R->A = SvIV( get_sv("M6502::A", FALSE) ); - printf("--1\n"); - R->P = atoi( SvPV_nolen( 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->P = SvIV( get_sv("M6502::P", 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 **/ @@ -64,13 +82,14 @@ byte = SvIV(sv); FREETMPS; LEAVE; - debugf(("Rd6502(%04x) = %02x\n", Addr, byte)); + //debugf(("mem(%04x) = %02x\n", Addr, byte)); return byte; } byte Rd6502(register word Addr) { byte Value; Value = mem(Addr); + debugf(("Rd6502(%04x) = %02x\n", Addr, Value)); return Value; } @@ -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() ***********************************************/ @@ -145,8 +164,6 @@ exit(1); } - update_R(R); - printf("reset CPU\n"); Reset6502(R); @@ -155,9 +172,15 @@ PUSHMARK(SP); call_pv("Arch::init", G_DISCARD | G_NOARGS ); - 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);