/[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 74 by dpavlin, Tue Jul 31 23:48:19 2007 UTC revision 81 by dpavlin, Wed Aug 1 15:53:54 2007 UTC
# Line 65  void push_R(M6502 *R) { Line 65  void push_R(M6502 *R) {
65          LEAVE;          LEAVE;
66  }  }
67    
68    byte Debug6502(M6502 *R) {
69            dump_R;
70            return 1; // continue emulation
71    }
72    
73  /** Rd6502()/Wr6502/Op6502() *********************************/  /** Rd6502()/Wr6502/Op6502() *********************************/
74  /** These functions are called when access to RAM occurs.   **/  /** These functions are called when access to RAM occurs.   **/
75  /** They allow to control memory access. Op6502 is the same **/  /** They allow to control memory access. Op6502 is the same **/
# Line 156  byte Patch6502(register byte Op,register Line 161  byte Patch6502(register byte Op,register
161          return 0;          return 0;
162  }  }
163    
164    void run_forever(void) {
165            printf("entered run_forever\n");
166    
167            R = malloc(sizeof(M6502));
168            if (!R) {
169                    printf("can't alloc %d bytes for M6502", sizeof(M6502));
170                    exit(1);
171            }
172    
173            printf("reset CPU\n");
174            Reset6502(R);
175    
176            printf("call Arch::init\n");
177            dSP;
178            PUSHMARK(SP);
179            call_pv("Arch::init", G_DISCARD | G_NOARGS );
180            FREETMPS;
181            LEAVE;
182    
183            int cycles = 1;
184            while ( cycles ) {
185                    dSP;
186                    PUSHMARK(SP);
187                    call_pv("Arch::cli", G_DISCARD | G_NOARGS );
188                    pull_R(R);
189                    FREETMPS;
190                    LEAVE;
191                    cycles = SvIV( get_sv("M6502::run_for", FALSE) );
192                    if ( cycles > 0 ) {
193                            printf("run CPU for %d cycles\n", cycles);
194                            dump_R;
195                            //Run6502(R);
196                            Exec6502(R, cycles);
197                            dump_R;
198                            push_R(R);
199                            printf("end of %d cycles CPU run\n", cycles);
200                    } else {
201                            printf("no cpu cycles set for run\n");
202                            cycles = 1; // never exit, prevents segfault
203                    }
204            }
205            free(R);
206    }
207    
208  /**  /**
209   * main code   * main code
210   *   *
# Line 174  int main(int argc, char **argv) { Line 223  int main(int argc, char **argv) {
223                  printf("Failed to execute\n");                  printf("Failed to execute\n");
224                  return 0;                  return 0;
225          } else {          } else {
226                  R = malloc(sizeof(M6502));                  run_forever();
                 if (!R) {  
                         printf("can't alloc %d bytes for M6502", sizeof(M6502));  
                         exit(1);  
                 }  
   
                 printf("reset CPU\n");  
                 Reset6502(R);  
   
                 printf("call Arch::init\n");  
                 dSP;  
                 PUSHMARK(SP);  
                 call_pv("Arch::init", G_DISCARD | G_NOARGS );  
                 FREETMPS;  
                 LEAVE;  
   
                 int cycles = 1;  
                 while ( cycles ) {  
                         dSP;  
                         PUSHMARK(SP);  
                         call_pv("Arch::cli", G_DISCARD | G_NOARGS );  
                         pull_R(R);  
                         FREETMPS;  
                         LEAVE;  
                         cycles = SvIV( get_sv("M6502::run_for", FALSE) );  
                         if ( cycles > 0 ) {  
                                 printf("run CPU for %d cycles\n", cycles);  
                                 dump_R;  
                                 //Run6502(R);  
                                 Exec6502(R, cycles);  
                                 dump_R;  
                                 push_R(R);  
                                 printf("end of %d cycles CPU run\n", cycles);  
                         } else {  
                                 printf("no cpu cycles set for run\n");  
                                 cycles = 1; // never exit, prevents segfault  
                         }  
                 }  
227          }          }
         free(R);  
228          perl_destruct(my_perl);          perl_destruct(my_perl);
229          perl_free(my_perl);          perl_free(my_perl);
230          return 0;          return 0;

Legend:
Removed from v.74  
changed lines
  Added in v.81

  ViewVC Help
Powered by ViewVC 1.1.26