/[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 26 by dpavlin, Mon Jul 30 14:23:22 2007 UTC revision 38 by dpavlin, Mon Jul 30 23:28:25 2007 UTC
# Line 3  Line 3 
3  #include "M6502.h"  #include "M6502.h"
4  #include "config.h"  #include "config.h"
5    
6    #if 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 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
21  void update_R(M6502 *R) {  #define dump_R
22          R->A = atoi( SvPV_nolen( get_sv("M6502::A", FALSE) ) );  #endif
23          R->P = atoi( SvPV_nolen( get_sv("M6502::P", FALSE) ) );  
24          R->X = atoi( SvPV_nolen( get_sv("M6502::X", FALSE) ) );  void pull_R(M6502 *R) {
25          R->Y = atoi( SvPV_nolen( get_sv("M6502::Y", FALSE) ) );          R->A = SvIV( get_sv("M6502::A", FALSE) );
26          R->S = atoi( SvPV_nolen( get_sv("M6502::S", FALSE) ) );          R->P = SvIV( get_sv("M6502::P", FALSE) );
27          R->PC.W = atoi( SvPV_nolen( get_sv("M6502::PC", FALSE) ) );          R->X = SvIV( get_sv("M6502::X", FALSE) );
28          R->IPeriod = atoi( SvPV_nolen( get_sv("M6502::IPeriod", FALSE) ) );          R->Y = SvIV( get_sv("M6502::Y", FALSE) );
29            R->S = SvIV( get_sv("M6502::S", FALSE) );
30            R->PC.W = SvIV( get_sv("M6502::PC", FALSE) );
31            R->IPeriod = SvIV( 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;
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;          dump_R;
52            FREETMPS;
53            LEAVE;
54  }  }
55    
56  /** Rd6502()/Wr6502/Op6502() *********************************/  /** Rd6502()/Wr6502/Op6502() *********************************/
# Line 29  void update_R(M6502 *R) { Line 61  void update_R(M6502 *R) {
61  /** required if there is a #define FAST_RDOP.               **/  /** required if there is a #define FAST_RDOP.               **/
62  /************************************ TO BE WRITTEN BY USER **/  /************************************ TO BE WRITTEN BY USER **/
63    
64    byte mem(word Addr) {
65            byte byte;
66            int count;
67            dSP;
68            ENTER;
69            SAVETMPS;
70            PUSHMARK(SP);
71            XPUSHs( sv_2mortal( newSViv( Addr ) ) );
72            PUTBACK;
73            count = call_pv("Arch::read", G_ARRAY );
74            if ( count != 1 ) {
75                    printf("expect 1 return value, got %d", count);
76                    exit(1);
77            }
78            //debugf(("got %d values\n", count));
79            SPAGAIN;
80            SV *sv;
81            sv = POPs;
82            byte = SvIV(sv);
83            FREETMPS;
84            LEAVE;
85            //debugf(("mem(%04x) = %02x\n", Addr, byte));
86            return byte;
87    }
88    
89  byte Rd6502(register word Addr) {  byte Rd6502(register word Addr) {
90          byte Value;          byte Value;
91          Value = 0x42;          Value = mem(Addr);
92          printf("Rd6502(%04x,%02x)\n", Addr, Value);          debugf(("Rd6502(%04x) = %02x\n", Addr, Value));
93            return Value;
94  }  }
95    
96  void Wr6502(register word Addr,register byte Value) {  void Wr6502(register word Addr,register byte Value) {
97          printf("Wr6502(%04x,%02x)\n", Addr, Value);          debugf(("Wr6502(%04x,%02x)\n", Addr, Value));
98            dSP;
99            ENTER;
100            SAVETMPS;
101            PUSHMARK(SP);
102            XPUSHs( sv_2mortal( newSViv( Addr ) ) );
103            XPUSHs( sv_2mortal( newSViv( Value ) ) );
104            PUTBACK;
105            call_pv("Arch::write", G_DISCARD );
106            FREETMPS;
107            LEAVE;
108  }  }
109    
110  byte Op6502(register word Addr) {  byte Op6502(register word Addr) {
111          byte Op;          byte Op;
112          Op = 0xff;          Op = mem(Addr);
113          printf("Op6502(%04x,%02x)\n", Addr, Op);          debugf(("Op6502(%04x,%02x) PC:%04x\n", Addr, Op, R->PC.W));
         dump_R;  
114  }  }
115    
116  /** Loop6502() ***********************************************/  /** Loop6502() ***********************************************/
# Line 54  byte Op6502(register word Addr) { Line 121  byte Op6502(register word Addr) {
121  /** emulation loop.                                         **/  /** emulation loop.                                         **/
122  /************************************ TO BE WRITTEN BY USER **/  /************************************ TO BE WRITTEN BY USER **/
123  byte Loop6502(register M6502 *R) {  byte Loop6502(register M6502 *R) {
124          printf("Loop6502\n");          debugf(("Loop6502\n"));
125          dump_R;          dump_R;
126            return INT_NONE;
127  }  }
128    
129  /** Patch6502() **********************************************/  /** Patch6502() **********************************************/
# Line 66  byte Loop6502(register M6502 *R) { Line 134  byte Loop6502(register M6502 *R) {
134  /** or 0 if the opcode was truly illegal.                   **/  /** or 0 if the opcode was truly illegal.                   **/
135  /************************************ TO BE WRITTEN BY USER **/  /************************************ TO BE WRITTEN BY USER **/
136  byte Patch6502(register byte Op,register M6502 *R) {  byte Patch6502(register byte Op,register M6502 *R) {
137          printf("Patch6502(%02x)\n", Op);          debugf(("Patch6502(%02x)\n", Op));
138          dump_R;          dump_R;
139            return 0;
140  }  }
141    
142  /**  /**
# Line 76  byte Patch6502(register byte Op,register Line 145  byte Patch6502(register byte Op,register
145   **/   **/
146    
147  int main(int argc, char **argv) {  int main(int argc, char **argv) {
148          char *command_line[] = {"", "-e",          char *command_line[] = {"", "-e", EMU_START };
                 "use M6502; print \"Loaded M6502 module\n\";"};  
149          my_perl = perl_alloc();          my_perl = perl_alloc();
150          perl_construct(my_perl);          perl_construct(my_perl);
151          if (perl_parse(my_perl, NULL, 3, command_line, (char **)NULL)) {          if (perl_parse(my_perl, xs_init, 3, command_line, (char **)NULL)) {
152                  printf("Failed to parse\n");                  printf("Failed to parse initial: %s\n", EMU_START );
153                  return 0;                  return 0;
154          }          }
155          perl_run(my_perl);          perl_run(my_perl);
# Line 95  int main(int argc, char **argv) { Line 163  int main(int argc, char **argv) {
163                          exit(1);                          exit(1);
164                  }                  }
165    
                 update_R(R);  
   
166                  printf("reset CPU\n");                  printf("reset CPU\n");
167                  Reset6502(R);                  Reset6502(R);
168    
169                  printf("call M6502::init\n");                  printf("call Arch::init\n");
170                  dSP;                  dSP;
171                  PUSHMARK(SP);                  PUSHMARK(SP);
172                  call_pv("M6502::init", G_DISCARD | G_NOARGS );                  call_pv("Arch::init", G_DISCARD | G_NOARGS );
173    
174                    pull_R(R);
175                  printf("run CPU\n");                  printf("run CPU\n");
176                  Run6502(R);                  dump_R;
177                    //Run6502(R);
178                    Exec6502(R, 10);
179                    dump_R;
180                    push_R(R);
181                    printf("end of CPU run\n");
182          }          }
183          free(R);          free(R);
184          perl_destruct(my_perl);          perl_destruct(my_perl);

Legend:
Removed from v.26  
changed lines
  Added in v.38

  ViewVC Help
Powered by ViewVC 1.1.26