/[VRac]/M6502/M6502.xs
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /M6502/M6502.xs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 87 - (hide annotations)
Thu Aug 2 11:08:10 2007 UTC (16 years, 9 months ago) by dpavlin
File size: 2194 byte(s)
- transfer debug state into C, added accesor M6502->debug();
- update_*_R functions to keep perl vars in sync with C
- tests
1 dpavlin 80 #include "EXTERN.h"
2     #include "perl.h"
3     #include "XSUB.h"
4    
5     #include "ppport.h"
6    
7 dpavlin 82 #include "M6502.h"
8     #include "config.h"
9    
10     M6502 *R;
11 dpavlin 87 int debug = 0;
12 dpavlin 82
13 dpavlin 87 void update_C_R(void) {
14     R->A = SvIV( get_sv("M6502::A", FALSE) );
15     R->P = SvIV( get_sv("M6502::P", FALSE) );
16     R->X = SvIV( get_sv("M6502::X", FALSE) );
17     R->Y = SvIV( get_sv("M6502::Y", FALSE) );
18     R->S = SvIV( get_sv("M6502::S", FALSE) );
19     R->PC.W = SvIV( get_sv("M6502::PC", FALSE) );
20     R->IPeriod = SvIV( get_sv("M6502::IPeriod", FALSE) );
21     R->IRequest = SvIV( get_sv("M6502::IRequest", FALSE) );
22     R->IAutoReset = SvIV( get_sv("M6502::IAutoReset", FALSE) );
23     R->TrapBadOps = SvIV( get_sv("M6502::TrapBadOps", FALSE) );
24     R->Trap = SvIV( get_sv("M6502::Trap", FALSE) );
25     R->Trace = SvIV( get_sv("M6502::Trace", FALSE) );
26     debugf(("pull_R finished"));
27     dump_R;
28 dpavlin 80 }
29    
30 dpavlin 87 void update_perl_R(void) {
31     debugf(("update_perl_R"));
32     dSP;
33     ENTER;
34     SAVETMPS;
35     PUSHMARK(SP);
36     XPUSHs( sv_2mortal( newSViv( R->A ) ) );
37     XPUSHs( sv_2mortal( newSViv( R->P ) ) );
38     XPUSHs( sv_2mortal( newSViv( R->X ) ) );
39     XPUSHs( sv_2mortal( newSViv( R->Y ) ) );
40     XPUSHs( sv_2mortal( newSViv( R->S ) ) );
41     XPUSHs( sv_2mortal( newSViv( R->PC.W ) ) );
42     XPUSHs( sv_2mortal( newSViv( R->IPeriod ) ) );
43     XPUSHs( sv_2mortal( newSViv( R->ICount ) ) );
44     XPUSHs( sv_2mortal( newSViv( R->IRequest ) ) );
45     XPUSHs( sv_2mortal( newSViv( R->IAutoReset ) ) );
46     XPUSHs( sv_2mortal( newSViv( R->TrapBadOps ) ) );
47     XPUSHs( sv_2mortal( newSViv( R->Trap ) ) );
48     XPUSHs( sv_2mortal( newSViv( R->Trace ) ) );
49     PUTBACK;
50     call_pv("M6502::_update_perl_R", G_DISCARD );
51     debugf(("_update_perl_R returned to C"));
52     dump_R;
53     FREETMPS;
54     LEAVE;
55     }
56    
57 dpavlin 84 int
58 dpavlin 82 reset (void) {
59     debugf(("M6502::reset called"));
60 dpavlin 83 if ( ! R ) {
61     debugf(("allocating space for R"));
62     R = malloc(sizeof(M6502));
63     if (!R) {
64 dpavlin 87 PerlIO_stderrf("can't alloc %d bytes for M6502", sizeof(M6502));
65 dpavlin 83 exit(1);
66     }
67     }
68 dpavlin 82 Reset6502(R);
69 dpavlin 84 debugf(("Reset6502 over"));
70 dpavlin 87 update_perl_R();
71 dpavlin 82 dump_R;
72 dpavlin 84 return 1;
73 dpavlin 82 }
74    
75 dpavlin 87 int set_debug(int state) {
76     debug = state;
77     return debug;
78     }
79 dpavlin 86
80 dpavlin 87 int get_debug(void) {
81     return debug;
82     }
83    
84 dpavlin 80 MODULE = M6502 PACKAGE = M6502
85    
86     PROTOTYPES: DISABLE
87    
88 dpavlin 87 int
89     set_debug(int state)
90 dpavlin 82
91 dpavlin 84 int
92 dpavlin 87 get_debug()
93    
94     int
95 dpavlin 82 reset()
96 dpavlin 87
97     void
98     update_C_R()
99    
100     void
101     update_perl_R()
102    

  ViewVC Help
Powered by ViewVC 1.1.26