--- M6502/M6502.xs 2007/08/01 22:01:15 84 +++ M6502/M6502.xs 2007/08/02 11:08:10 87 @@ -8,11 +8,50 @@ #include "config.h" M6502 *R; +int debug = 0; -void -run (void) { - debugf(("M6502::run")); - run_forever(); +void update_C_R(void) { + R->A = SvIV( get_sv("M6502::A", 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) ); + R->IRequest = SvIV( get_sv("M6502::IRequest", FALSE) ); + R->IAutoReset = SvIV( get_sv("M6502::IAutoReset", FALSE) ); + R->TrapBadOps = SvIV( get_sv("M6502::TrapBadOps", FALSE) ); + R->Trap = SvIV( get_sv("M6502::Trap", FALSE) ); + R->Trace = SvIV( get_sv("M6502::Trace", FALSE) ); + debugf(("pull_R finished")); + dump_R; +} + +void update_perl_R(void) { + debugf(("update_perl_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 ) ) ); + XPUSHs( sv_2mortal( newSViv( R->IPeriod ) ) ); + XPUSHs( sv_2mortal( newSViv( R->ICount ) ) ); + XPUSHs( sv_2mortal( newSViv( R->IRequest ) ) ); + XPUSHs( sv_2mortal( newSViv( R->IAutoReset ) ) ); + XPUSHs( sv_2mortal( newSViv( R->TrapBadOps ) ) ); + XPUSHs( sv_2mortal( newSViv( R->Trap ) ) ); + XPUSHs( sv_2mortal( newSViv( R->Trace ) ) ); + PUTBACK; + call_pv("M6502::_update_perl_R", G_DISCARD ); + debugf(("_update_perl_R returned to C")); + dump_R; + FREETMPS; + LEAVE; } int @@ -22,22 +61,42 @@ debugf(("allocating space for R")); R = malloc(sizeof(M6502)); if (!R) { - printf("can't alloc %d bytes for M6502", sizeof(M6502)); + PerlIO_stderrf("can't alloc %d bytes for M6502", sizeof(M6502)); exit(1); } } Reset6502(R); debugf(("Reset6502 over")); + update_perl_R(); dump_R; return 1; } +int set_debug(int state) { + debug = state; + return debug; +} + +int get_debug(void) { + return debug; +} + MODULE = M6502 PACKAGE = M6502 PROTOTYPES: DISABLE -void -run() +int +set_debug(int state) + +int +get_debug() int reset() + +void +update_C_R() + +void +update_perl_R() +