7 |
|
|
8 |
static M6502 *R; |
static M6502 *R; |
9 |
|
|
10 |
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 ); |
11 |
|
|
12 |
|
void update_R(M6502 *R) { |
13 |
|
R->A = atoi( SvPV_nolen( get_sv("M6502::A", TRUE) ) ); |
14 |
|
R->P = atoi( SvPV_nolen( get_sv("M6502::P", TRUE) ) ); |
15 |
|
R->X = atoi( SvPV_nolen( get_sv("M6502::X", TRUE) ) ); |
16 |
|
R->Y = atoi( SvPV_nolen( get_sv("M6502::Y", TRUE) ) ); |
17 |
|
R->S = atoi( SvPV_nolen( get_sv("M6502::S", TRUE) ) ); |
18 |
R->PC.W = atoi( SvPV_nolen( get_sv("M6502::PC", TRUE) ) ); |
R->PC.W = atoi( SvPV_nolen( get_sv("M6502::PC", TRUE) ) ); |
19 |
printf("PC: %04x\n", R->PC.W); |
R->IPeriod = atoi( SvPV_nolen( get_sv("M6502::IPeriod", TRUE) ) ); |
20 |
|
// ICount IRequest IAutoReset TrapBadOps Trap Trace |
21 |
|
dump_R; |
22 |
|
} |
23 |
|
|
24 |
|
/** Rd6502()/Wr6502/Op6502() *********************************/ |
25 |
|
/** These functions are called when access to RAM occurs. **/ |
26 |
|
/** They allow to control memory access. Op6502 is the same **/ |
27 |
|
/** as Rd6502, but used to read *opcodes* only, when many **/ |
28 |
|
/** checks can be skipped to make it fast. It is only **/ |
29 |
|
/** required if there is a #define FAST_RDOP. **/ |
30 |
|
/************************************ TO BE WRITTEN BY USER **/ |
31 |
|
|
32 |
|
byte Rd6502(register word Addr) { |
33 |
|
byte Value; |
34 |
|
Value = 0x42; |
35 |
|
printf("Rd6502(%04x,%02x)\n", Addr, Value); |
36 |
|
} |
37 |
|
|
38 |
|
void Wr6502(register word Addr,register byte Value) { |
39 |
|
printf("Wr6502(%04x,%02x)\n", Addr, Value); |
40 |
|
} |
41 |
|
|
42 |
|
byte Op6502(register word Addr) { |
43 |
|
byte Op; |
44 |
|
Op = 0xff; |
45 |
|
printf("Op6502(%04x,%02x)\n", Addr, Op); |
46 |
|
dump_R; |
47 |
|
} |
48 |
|
|
49 |
|
/** Loop6502() ***********************************************/ |
50 |
|
/** 6502 emulation calls this function periodically to **/ |
51 |
|
/** check if the system hardware requires any interrupts. **/ |
52 |
|
/** This function must return one of following values: **/ |
53 |
|
/** INT_NONE, INT_IRQ, INT_NMI, or INT_QUIT to exit the **/ |
54 |
|
/** emulation loop. **/ |
55 |
|
/************************************ TO BE WRITTEN BY USER **/ |
56 |
|
byte Loop6502(register M6502 *R) { |
57 |
|
printf("Loop6502\n"); |
58 |
|
dump_R; |
59 |
} |
} |
60 |
|
|
61 |
|
/** Patch6502() **********************************************/ |
62 |
|
/** Emulation calls this function when it encounters an **/ |
63 |
|
/** unknown opcode. This can be used to patch the code to **/ |
64 |
|
/** emulate BIOS calls, such as disk and tape access. The **/ |
65 |
|
/** function should return 1 if the exception was handled, **/ |
66 |
|
/** or 0 if the opcode was truly illegal. **/ |
67 |
|
/************************************ TO BE WRITTEN BY USER **/ |
68 |
|
byte Patch6502(register byte Op,register M6502 *R) { |
69 |
|
printf("Patch6502(%02x)\n", Op); |
70 |
|
dump_R; |
71 |
|
} |
72 |
|
|
73 |
|
/** |
74 |
|
* main code |
75 |
|
* |
76 |
|
**/ |
77 |
|
|
78 |
int main(int argc, char **argv) { |
int main(int argc, char **argv) { |
79 |
char *command_line[] = {"", "-e", |
char *command_line[] = {"", "-e", |
80 |
"use M6502; print \"Loaded M6502 module\n\";"}; |
"use M6502; print \"Loaded M6502 module\n\";"}; |
94 |
printf("can't alloc %d bytes for M6502", sizeof(M6502)); |
printf("can't alloc %d bytes for M6502", sizeof(M6502)); |
95 |
exit(1); |
exit(1); |
96 |
} |
} |
97 |
|
update_R(R); |
98 |
printf("reset CPU\n"); |
printf("reset CPU\n"); |
99 |
Reset6502(R); |
Reset6502(R); |
100 |
|
printf("reset CPU\n"); |
101 |
|
Run6502(R); |
102 |
|
|
103 |
} |
} |
104 |
free(R); |
free(R); |