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

Diff of /M6502/perl.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 33 by dpavlin, Mon Jul 30 21:00:36 2007 UTC revision 40 by dpavlin, Tue Jul 31 08:41:06 2007 UTC
# Line 3  Line 3 
3  #include "M6502.h"  #include "M6502.h"
4  #include "config.h"  #include "config.h"
5    
6  #ifdef DEBUGF  #if DEBUGF
7  #define debugf(x)  do {         \  #define debugf(x)  do {         \
8          PerlIO_stdoutf x ;      \          PerlIO_stdoutf x ;      \
9  } while (0)  } while (0)
# Line 15  static PerlInterpreter *my_perl; Line 15  static PerlInterpreter *my_perl;
15    
16  static M6502 *R;  static M6502 *R;
17    
18  #if 0  #if DUMP_R
19  #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 );  #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 );
20  #else  #else
21  #define dump_R  #define dump_R
22  #endif  #endif
23    
24  void update_R(M6502 *R) {  void pull_R(M6502 *R) {
         printf("--0\n");  
25          R->A = SvIV( get_sv("M6502::A", FALSE) );          R->A = SvIV( get_sv("M6502::A", FALSE) );
26          printf("--1\n");          R->P = SvIV( get_sv("M6502::P", FALSE) );
27          R->P = atoi( SvPV_nolen( get_sv("M6502::P", FALSE) ) );          R->X = SvIV( get_sv("M6502::X", FALSE) );
28          R->X = atoi( SvPV_nolen( get_sv("M6502::X", FALSE) ) );          R->Y = SvIV( get_sv("M6502::Y", FALSE) );
29          R->Y = atoi( SvPV_nolen( get_sv("M6502::Y", FALSE) ) );          R->S = SvIV( get_sv("M6502::S", FALSE) );
30          R->S = atoi( SvPV_nolen( get_sv("M6502::S", FALSE) ) );          R->PC.W = SvIV( get_sv("M6502::PC", FALSE) );
31          R->PC.W = atoi( SvPV_nolen( get_sv("M6502::PC", FALSE) ) );          R->IPeriod = SvIV( get_sv("M6502::IPeriod", FALSE) );
         R->IPeriod = atoi( SvPV_nolen( get_sv("M6502::IPeriod", FALSE) ) );  
32          // ICount IRequest IAutoReset TrapBadOps Trap Trace          // ICount IRequest IAutoReset TrapBadOps Trap Trace
33            printf("pull_R finished\n");
34          dump_R;          dump_R;
35  }  }
36    
37    void push_R(M6502 *R) {
38            dSP;
39            ENTER;
40            SAVETMPS;
41            PUSHMARK(SP);
42            XPUSHs( sv_2mortal( newSViv( R->A ) ) );
43            XPUSHs( sv_2mortal( newSViv( R->P ) ) );
44            XPUSHs( sv_2mortal( newSViv( R->X ) ) );
45            XPUSHs( sv_2mortal( newSViv( R->Y ) ) );
46            XPUSHs( sv_2mortal( newSViv( R->S ) ) );
47            XPUSHs( sv_2mortal( newSViv( R->PC.W ) ) );
48            PUTBACK;
49            call_pv("M6502::push_R", G_DISCARD );
50            printf("push_R called\n");
51            dump_R;
52            FREETMPS;
53            LEAVE;
54    }
55    
56  /** Rd6502()/Wr6502/Op6502() *********************************/  /** Rd6502()/Wr6502/Op6502() *********************************/
57  /** These functions are called when access to RAM occurs.   **/  /** These functions are called when access to RAM occurs.   **/
58  /** They allow to control memory access. Op6502 is the same **/  /** They allow to control memory access. Op6502 is the same **/
# Line 64  byte mem(word Addr) { Line 82  byte mem(word Addr) {
82          byte = SvIV(sv);          byte = SvIV(sv);
83          FREETMPS;          FREETMPS;
84          LEAVE;          LEAVE;
85          debugf(("Rd6502(%04x) = %02x\n", Addr, byte));          //debugf(("mem(%04x) = %02x\n", Addr, byte));
86          return byte;          return byte;
87  }  }
88    
89  byte Rd6502(register word Addr) {  byte Rd6502(register word Addr) {
90          byte Value;          byte Value;
91          Value = mem(Addr);          Value = mem(Addr);
92            debugf(("Rd6502(%04x) = %02x\n", Addr, Value));
93          return Value;          return Value;
94  }  }
95    
# Line 91  void Wr6502(register word Addr,register Line 110  void Wr6502(register word Addr,register
110  byte Op6502(register word Addr) {  byte Op6502(register word Addr) {
111          byte Op;          byte Op;
112          Op = mem(Addr);          Op = mem(Addr);
113          debugf(("Op6502(%04x,%02x)\n", Addr, Op));          debugf(("Op6502(%04x,%02x) PC:%04x\n", Addr, Op, R->PC.W));
114          dump_R;          return Op;
115  }  }
116    
117  /** Loop6502() ***********************************************/  /** Loop6502() ***********************************************/
# Line 145  int main(int argc, char **argv) { Line 164  int main(int argc, char **argv) {
164                          exit(1);                          exit(1);
165                  }                  }
166    
                 update_R(R);  
   
167                  printf("reset CPU\n");                  printf("reset CPU\n");
168                  Reset6502(R);                  Reset6502(R);
169    
# Line 155  int main(int argc, char **argv) { Line 172  int main(int argc, char **argv) {
172                  PUSHMARK(SP);                  PUSHMARK(SP);
173                  call_pv("Arch::init", G_DISCARD | G_NOARGS );                  call_pv("Arch::init", G_DISCARD | G_NOARGS );
174    
175                  printf("run CPU\n");                  pull_R(R);
176                  Run6502(R);                  int cycles = SvIV( get_sv("M6502::run_for", FALSE) );
177                    printf("run CPU for %d cycles\n", cycles);
178                    dump_R;
179                    //Run6502(R);
180                    Exec6502(R, cycles);
181                    dump_R;
182                    push_R(R);
183                    printf("end of CPU run\n");
184          }          }
185          free(R);          free(R);
186          perl_destruct(my_perl);          perl_destruct(my_perl);

Legend:
Removed from v.33  
changed lines
  Added in v.40

  ViewVC Help
Powered by ViewVC 1.1.26