/[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 31 by dpavlin, Mon Jul 30 18:07:29 2007 UTC revision 33 by dpavlin, Mon Jul 30 21:00:36 2007 UTC
# Line 3  Line 3 
3  #include "M6502.h"  #include "M6502.h"
4  #include "config.h"  #include "config.h"
5    
6    #ifdef DEBUGF
7    #define debugf(x)  do {         \
8            PerlIO_stdoutf x ;      \
9    } while (0)
10    #else
11    #define debugf(x)
12    #endif
13    
14  static PerlInterpreter *my_perl;  static PerlInterpreter *my_perl;
15    
16  static M6502 *R;  static M6502 *R;
17    
18    #if 0
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
21    #define dump_R
22    #endif
23    
24  void update_R(M6502 *R) {  void update_R(M6502 *R) {
25          R->A = atoi( SvPV_nolen( get_sv("M6502::A", FALSE) ) );          printf("--0\n");
26            R->A = SvIV( get_sv("M6502::A", FALSE) );
27            printf("--1\n");
28          R->P = atoi( SvPV_nolen( get_sv("M6502::P", FALSE) ) );          R->P = atoi( SvPV_nolen( get_sv("M6502::P", FALSE) ) );
29          R->X = atoi( SvPV_nolen( get_sv("M6502::X", FALSE) ) );          R->X = atoi( SvPV_nolen( get_sv("M6502::X", FALSE) ) );
30          R->Y = atoi( SvPV_nolen( get_sv("M6502::Y", FALSE) ) );          R->Y = atoi( SvPV_nolen( get_sv("M6502::Y", FALSE) ) );
# Line 38  byte mem(word Addr) { Line 52  byte mem(word Addr) {
52          PUSHMARK(SP);          PUSHMARK(SP);
53          XPUSHs( sv_2mortal( newSViv( Addr ) ) );          XPUSHs( sv_2mortal( newSViv( Addr ) ) );
54          PUTBACK;          PUTBACK;
55          count = call_pv("M6502::read", G_ARRAY );          count = call_pv("Arch::read", G_ARRAY );
56          if ( count != 1 ) {          if ( count != 1 ) {
57                  printf("expect 1 return value, got %d", count);                  printf("expect 1 return value, got %d", count);
58                  exit(1);                  exit(1);
59          }          }
60          printf("got %d values\n", count);          //debugf(("got %d values\n", count));
61          SPAGAIN;          SPAGAIN;
62          SV *sv;          SV *sv;
63          sv = POPs;          sv = POPs;
64          byte = SvIV(sv);          byte = SvIV(sv);
65          FREETMPS;          FREETMPS;
66          LEAVE;          LEAVE;
67          printf("Rd6502(%04x) = %02x\n", Addr, byte);          debugf(("Rd6502(%04x) = %02x\n", Addr, byte));
68          return byte;          return byte;
69  }  }
70    
# Line 61  byte Rd6502(register word Addr) { Line 75  byte Rd6502(register word Addr) {
75  }  }
76    
77  void Wr6502(register word Addr,register byte Value) {  void Wr6502(register word Addr,register byte Value) {
78          printf("Wr6502(%04x,%02x)\n", Addr, Value);          debugf(("Wr6502(%04x,%02x)\n", Addr, Value));
79          dSP;          dSP;
80          ENTER;          ENTER;
81          SAVETMPS;          SAVETMPS;
# Line 69  void Wr6502(register word Addr,register Line 83  void Wr6502(register word Addr,register
83          XPUSHs( sv_2mortal( newSViv( Addr ) ) );          XPUSHs( sv_2mortal( newSViv( Addr ) ) );
84          XPUSHs( sv_2mortal( newSViv( Value ) ) );          XPUSHs( sv_2mortal( newSViv( Value ) ) );
85          PUTBACK;          PUTBACK;
86          call_pv("M6502::write", G_DISCARD );          call_pv("Arch::write", G_DISCARD );
87          FREETMPS;          FREETMPS;
88          LEAVE;          LEAVE;
89  }  }
# Line 77  void Wr6502(register word Addr,register Line 91  void Wr6502(register word Addr,register
91  byte Op6502(register word Addr) {  byte Op6502(register word Addr) {
92          byte Op;          byte Op;
93          Op = mem(Addr);          Op = mem(Addr);
94          printf("Op6502(%04x,%02x)\n", Addr, Op);          debugf(("Op6502(%04x,%02x)\n", Addr, Op));
95          dump_R;          dump_R;
96  }  }
97    
# Line 89  byte Op6502(register word Addr) { Line 103  byte Op6502(register word Addr) {
103  /** emulation loop.                                         **/  /** emulation loop.                                         **/
104  /************************************ TO BE WRITTEN BY USER **/  /************************************ TO BE WRITTEN BY USER **/
105  byte Loop6502(register M6502 *R) {  byte Loop6502(register M6502 *R) {
106          printf("Loop6502\n");          debugf(("Loop6502\n"));
107          dump_R;          dump_R;
108          return INT_NONE;          return INT_NONE;
109  }  }
# Line 102  byte Loop6502(register M6502 *R) { Line 116  byte Loop6502(register M6502 *R) {
116  /** or 0 if the opcode was truly illegal.                   **/  /** or 0 if the opcode was truly illegal.                   **/
117  /************************************ TO BE WRITTEN BY USER **/  /************************************ TO BE WRITTEN BY USER **/
118  byte Patch6502(register byte Op,register M6502 *R) {  byte Patch6502(register byte Op,register M6502 *R) {
119          printf("Patch6502(%02x)\n", Op);          debugf(("Patch6502(%02x)\n", Op));
120          dump_R;          dump_R;
121          return 0;          return 0;
122  }  }
# Line 136  int main(int argc, char **argv) { Line 150  int main(int argc, char **argv) {
150                  printf("reset CPU\n");                  printf("reset CPU\n");
151                  Reset6502(R);                  Reset6502(R);
152    
153                  printf("call M6502::init\n");                  printf("call Arch::init\n");
154                  dSP;                  dSP;
155                  PUSHMARK(SP);                  PUSHMARK(SP);
156                  call_pv("M6502::init", G_DISCARD | G_NOARGS );                  call_pv("Arch::init", G_DISCARD | G_NOARGS );
157    
158                  printf("run CPU\n");                  printf("run CPU\n");
159                  Run6502(R);                  Run6502(R);

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

  ViewVC Help
Powered by ViewVC 1.1.26