/[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 25 by dpavlin, Mon Jul 30 14:02:31 2007 UTC revision 28 by dpavlin, Mon Jul 30 15:52:22 2007 UTC
# Line 7  static PerlInterpreter *my_perl; Line 7  static PerlInterpreter *my_perl;
7    
8  static M6502 *R;  static M6502 *R;
9    
10  #define dump_R printf("PC: %04x A:%02x P:%02x X:%02x Y:%02x S:%02x", 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 );
11    
12  void update_R(M6502 *R) {  void update_R(M6502 *R) {
13          R->A = atoi( SvPV_nolen( get_sv("M6502::A", TRUE) ) );          R->A = atoi( SvPV_nolen( get_sv("M6502::A", FALSE) ) );
14          R->P = atoi( SvPV_nolen( get_sv("M6502::P", TRUE) ) );          R->P = atoi( SvPV_nolen( get_sv("M6502::P", FALSE) ) );
15          R->X = atoi( SvPV_nolen( get_sv("M6502::X", TRUE) ) );          R->X = atoi( SvPV_nolen( get_sv("M6502::X", FALSE) ) );
16          R->Y = atoi( SvPV_nolen( get_sv("M6502::Y", TRUE) ) );          R->Y = atoi( SvPV_nolen( get_sv("M6502::Y", FALSE) ) );
17          R->S = atoi( SvPV_nolen( get_sv("M6502::S", TRUE) ) );          R->S = atoi( SvPV_nolen( get_sv("M6502::S", FALSE) ) );
18          R->PC.W = atoi( SvPV_nolen( get_sv("M6502::PC", TRUE) ) );          R->PC.W = atoi( SvPV_nolen( get_sv("M6502::PC", FALSE) ) );
19          R->IPeriod = atoi( SvPV_nolen( get_sv("M6502::IPeriod", TRUE) ) );          R->IPeriod = atoi( SvPV_nolen( get_sv("M6502::IPeriod", FALSE) ) );
20          // ICount IRequest IAutoReset TrapBadOps Trap Trace          // ICount IRequest IAutoReset TrapBadOps Trap Trace
21          dump_R;          dump_R;
22  }  }
# Line 29  void update_R(M6502 *R) { Line 29  void update_R(M6502 *R) {
29  /** required if there is a #define FAST_RDOP.               **/  /** required if there is a #define FAST_RDOP.               **/
30  /************************************ TO BE WRITTEN BY USER **/  /************************************ TO BE WRITTEN BY USER **/
31    
32    byte mem(word Addr) {
33            byte byte;
34            int count;
35            dSP;
36            ENTER;
37            SAVETMPS;
38            PUSHMARK(SP);
39            XPUSHs( sv_2mortal( newSViv( Addr ) ) );
40            PUTBACK;
41            count = call_pv("M6502::read", G_ARRAY );
42            if ( count != 1 ) {
43                    printf("expect 1 return value, got %d", count);
44                    exit(1);
45            }
46            printf("got %d values\n", count);
47            SPAGAIN;
48            SV *sv;
49            sv = POPs;
50            byte = SvIV(sv);
51            FREETMPS;
52            LEAVE;
53            printf("Rd6502(%04x) = %02x\n", Addr, byte);
54            return byte;
55    }
56    
57  byte Rd6502(register word Addr) {  byte Rd6502(register word Addr) {
58          byte Value;          byte Value;
59          Value = 0x42;          Value = mem(Addr);
60          printf("Rd6502(%04x,%02x)\n", Addr, Value);          return Value;
61  }  }
62    
63  void Wr6502(register word Addr,register byte Value) {  void Wr6502(register word Addr,register byte Value) {
64          printf("Wr6502(%04x,%02x)\n", Addr, Value);          printf("Wr6502(%04x,%02x)\n", Addr, Value);
65            dSP;
66            ENTER;
67            SAVETMPS;
68            PUSHMARK(SP);
69            XPUSHs( sv_2mortal( newSViv( Addr ) ) );
70            XPUSHs( sv_2mortal( newSViv( Value ) ) );
71            PUTBACK;
72            call_pv("M6502::write", G_DISCARD );
73            FREETMPS;
74            LEAVE;
75  }  }
76    
77  byte Op6502(register word Addr) {  byte Op6502(register word Addr) {
78          byte Op;          byte Op;
79          Op = 0xff;          Op = mem(Addr);
80          printf("Op6502(%04x,%02x)\n", Addr, Op);          printf("Op6502(%04x,%02x)\n", Addr, Op);
81          dump_R;          dump_R;
82  }  }
# Line 56  byte Op6502(register word Addr) { Line 91  byte Op6502(register word Addr) {
91  byte Loop6502(register M6502 *R) {  byte Loop6502(register M6502 *R) {
92          printf("Loop6502\n");          printf("Loop6502\n");
93          dump_R;          dump_R;
94            return INT_NONE;
95  }  }
96    
97  /** Patch6502() **********************************************/  /** Patch6502() **********************************************/
# Line 68  byte Loop6502(register M6502 *R) { Line 104  byte Loop6502(register M6502 *R) {
104  byte Patch6502(register byte Op,register M6502 *R) {  byte Patch6502(register byte Op,register M6502 *R) {
105          printf("Patch6502(%02x)\n", Op);          printf("Patch6502(%02x)\n", Op);
106          dump_R;          dump_R;
107            return 0;
108  }  }
109    
110  /**  /**
# Line 94  int main(int argc, char **argv) { Line 131  int main(int argc, char **argv) {
131                          printf("can't alloc %d bytes for M6502", sizeof(M6502));                          printf("can't alloc %d bytes for M6502", sizeof(M6502));
132                          exit(1);                          exit(1);
133                  }                  }
134    
135                  update_R(R);                  update_R(R);
136    
137                  printf("reset CPU\n");                  printf("reset CPU\n");
138                  Reset6502(R);                  Reset6502(R);
139                  printf("reset CPU\n");  
140                    printf("call M6502::init\n");
141                    dSP;
142                    PUSHMARK(SP);
143                    call_pv("M6502::init", G_DISCARD | G_NOARGS );
144    
145                    printf("run CPU\n");
146                  Run6502(R);                  Run6502(R);
147    
148          }          }

Legend:
Removed from v.25  
changed lines
  Added in v.28

  ViewVC Help
Powered by ViewVC 1.1.26