--- M6502/perl.c 2007/07/30 13:29:57 24 +++ M6502/perl.c 2007/07/30 14:02:31 25 @@ -7,11 +7,74 @@ static M6502 *R; -void Reset6502(M6502 *R) { +#define dump_R printf("PC: %04x A:%02x P:%02x X:%02x Y:%02x S:%02x", R->PC.W, R->A, R->P, R->X, R->Y, R->S ); + +void update_R(M6502 *R) { + R->A = atoi( SvPV_nolen( get_sv("M6502::A", TRUE) ) ); + R->P = atoi( SvPV_nolen( get_sv("M6502::P", TRUE) ) ); + R->X = atoi( SvPV_nolen( get_sv("M6502::X", TRUE) ) ); + R->Y = atoi( SvPV_nolen( get_sv("M6502::Y", TRUE) ) ); + R->S = atoi( SvPV_nolen( get_sv("M6502::S", TRUE) ) ); R->PC.W = atoi( SvPV_nolen( get_sv("M6502::PC", TRUE) ) ); - printf("PC: %04x\n", R->PC.W); + R->IPeriod = atoi( SvPV_nolen( get_sv("M6502::IPeriod", TRUE) ) ); + // ICount IRequest IAutoReset TrapBadOps Trap Trace + dump_R; +} + +/** Rd6502()/Wr6502/Op6502() *********************************/ +/** These functions are called when access to RAM occurs. **/ +/** They allow to control memory access. Op6502 is the same **/ +/** as Rd6502, but used to read *opcodes* only, when many **/ +/** checks can be skipped to make it fast. It is only **/ +/** required if there is a #define FAST_RDOP. **/ +/************************************ TO BE WRITTEN BY USER **/ + +byte Rd6502(register word Addr) { + byte Value; + Value = 0x42; + printf("Rd6502(%04x,%02x)\n", Addr, Value); +} + +void Wr6502(register word Addr,register byte Value) { + printf("Wr6502(%04x,%02x)\n", Addr, Value); +} + +byte Op6502(register word Addr) { + byte Op; + Op = 0xff; + printf("Op6502(%04x,%02x)\n", Addr, Op); + dump_R; +} + +/** Loop6502() ***********************************************/ +/** 6502 emulation calls this function periodically to **/ +/** check if the system hardware requires any interrupts. **/ +/** This function must return one of following values: **/ +/** INT_NONE, INT_IRQ, INT_NMI, or INT_QUIT to exit the **/ +/** emulation loop. **/ +/************************************ TO BE WRITTEN BY USER **/ +byte Loop6502(register M6502 *R) { + printf("Loop6502\n"); + dump_R; } +/** Patch6502() **********************************************/ +/** Emulation calls this function when it encounters an **/ +/** unknown opcode. This can be used to patch the code to **/ +/** emulate BIOS calls, such as disk and tape access. The **/ +/** function should return 1 if the exception was handled, **/ +/** or 0 if the opcode was truly illegal. **/ +/************************************ TO BE WRITTEN BY USER **/ +byte Patch6502(register byte Op,register M6502 *R) { + printf("Patch6502(%02x)\n", Op); + dump_R; +} + +/** + * main code + * + **/ + int main(int argc, char **argv) { char *command_line[] = {"", "-e", "use M6502; print \"Loaded M6502 module\n\";"}; @@ -31,8 +94,11 @@ printf("can't alloc %d bytes for M6502", sizeof(M6502)); exit(1); } + update_R(R); printf("reset CPU\n"); Reset6502(R); + printf("reset CPU\n"); + Run6502(R); } free(R);