7 |
|
|
8 |
static M6502 *R; |
static M6502 *R; |
9 |
|
|
10 |
#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 ); |
#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 ); |
11 |
|
|
12 |
void update_R(M6502 *R) { |
void update_R(M6502 *R) { |
13 |
R->A = atoi( SvPV_nolen( get_sv("M6502::A", TRUE) ) ); |
R->A = atoi( SvPV_nolen( get_sv("M6502::A", FALSE) ) ); |
14 |
R->P = atoi( SvPV_nolen( get_sv("M6502::P", TRUE) ) ); |
R->P = atoi( SvPV_nolen( get_sv("M6502::P", FALSE) ) ); |
15 |
R->X = atoi( SvPV_nolen( get_sv("M6502::X", TRUE) ) ); |
R->X = atoi( SvPV_nolen( get_sv("M6502::X", FALSE) ) ); |
16 |
R->Y = atoi( SvPV_nolen( get_sv("M6502::Y", TRUE) ) ); |
R->Y = atoi( SvPV_nolen( get_sv("M6502::Y", FALSE) ) ); |
17 |
R->S = atoi( SvPV_nolen( get_sv("M6502::S", TRUE) ) ); |
R->S = atoi( SvPV_nolen( get_sv("M6502::S", FALSE) ) ); |
18 |
R->PC.W = atoi( SvPV_nolen( get_sv("M6502::PC", TRUE) ) ); |
R->PC.W = atoi( SvPV_nolen( get_sv("M6502::PC", FALSE) ) ); |
19 |
R->IPeriod = atoi( SvPV_nolen( get_sv("M6502::IPeriod", TRUE) ) ); |
R->IPeriod = atoi( SvPV_nolen( get_sv("M6502::IPeriod", FALSE) ) ); |
20 |
// ICount IRequest IAutoReset TrapBadOps Trap Trace |
// ICount IRequest IAutoReset TrapBadOps Trap Trace |
21 |
dump_R; |
dump_R; |
22 |
} |
} |
33 |
byte Value; |
byte Value; |
34 |
Value = 0x42; |
Value = 0x42; |
35 |
printf("Rd6502(%04x,%02x)\n", Addr, Value); |
printf("Rd6502(%04x,%02x)\n", Addr, Value); |
36 |
|
|
37 |
|
int count; |
38 |
|
dSP; |
39 |
|
ENTER; |
40 |
|
SAVETMPS; |
41 |
|
PUSHMARK(SP); |
42 |
|
XPUSHs( sv_2mortal( newSViv( Value ) ) ); |
43 |
|
PUTBACK; |
44 |
|
count = call_pv("M6502::read", G_ARRAY ); |
45 |
|
if ( count != 1 ) { |
46 |
|
printf("expect 1 return value, got %d", count); |
47 |
|
exit(1); |
48 |
|
} |
49 |
|
printf("got %d values\n", count); |
50 |
|
SPAGAIN; |
51 |
|
SV *sv; |
52 |
|
sv = POPs; |
53 |
|
Value = SvIV(sv); |
54 |
|
// Value = savepv(SvPV_nolen(POPs)); |
55 |
|
FREETMPS; |
56 |
|
LEAVE; |
57 |
|
printf("Rd6502(%04x) = %02x\n", Addr, Value); |
58 |
|
return Value; |
59 |
} |
} |
60 |
|
|
61 |
void Wr6502(register word Addr,register byte Value) { |
void Wr6502(register word Addr,register byte Value) { |
62 |
printf("Wr6502(%04x,%02x)\n", Addr, Value); |
printf("Wr6502(%04x,%02x)\n", Addr, Value); |
63 |
|
dSP; |
64 |
|
ENTER; |
65 |
|
SAVETMPS; |
66 |
|
PUSHMARK(SP); |
67 |
|
XPUSHs( sv_2mortal( newSViv( Addr ) ) ); |
68 |
|
XPUSHs( sv_2mortal( newSViv( Value ) ) ); |
69 |
|
PUTBACK; |
70 |
|
call_pv("M6502::write", G_DISCARD ); |
71 |
|
FREETMPS; |
72 |
|
LEAVE; |
73 |
} |
} |
74 |
|
|
75 |
byte Op6502(register word Addr) { |
byte Op6502(register word Addr) { |
127 |
printf("can't alloc %d bytes for M6502", sizeof(M6502)); |
printf("can't alloc %d bytes for M6502", sizeof(M6502)); |
128 |
exit(1); |
exit(1); |
129 |
} |
} |
130 |
|
|
131 |
update_R(R); |
update_R(R); |
132 |
|
|
133 |
printf("reset CPU\n"); |
printf("reset CPU\n"); |
134 |
Reset6502(R); |
Reset6502(R); |
135 |
printf("reset CPU\n"); |
|
136 |
|
printf("call M6502::init\n"); |
137 |
|
dSP; |
138 |
|
PUSHMARK(SP); |
139 |
|
call_pv("M6502::init", G_DISCARD | G_NOARGS ); |
140 |
|
|
141 |
|
printf("run CPU\n"); |
142 |
Run6502(R); |
Run6502(R); |
143 |
|
|
144 |
} |
} |