/[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 24 by dpavlin, Mon Jul 30 13:29:57 2007 UTC revision 27 by dpavlin, Mon Jul 30 15:45:03 2007 UTC
# Line 7  static PerlInterpreter *my_perl; Line 7  static PerlInterpreter *my_perl;
7    
8  static M6502 *R;  static M6502 *R;
9    
10  void Reset6502(M6502 *R) {  #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          R->PC.W = atoi( SvPV_nolen( get_sv("M6502::PC", TRUE) ) );  
12          printf("PC: %04x\n", R->PC.W);  void update_R(M6502 *R) {
13            R->A = atoi( SvPV_nolen( get_sv("M6502::A", FALSE) ) );
14            R->P = atoi( SvPV_nolen( get_sv("M6502::P", FALSE) ) );
15            R->X = atoi( SvPV_nolen( get_sv("M6502::X", FALSE) ) );
16            R->Y = atoi( SvPV_nolen( get_sv("M6502::Y", FALSE) ) );
17            R->S = atoi( SvPV_nolen( get_sv("M6502::S", FALSE) ) );
18            R->PC.W = atoi( SvPV_nolen( get_sv("M6502::PC", FALSE) ) );
19            R->IPeriod = atoi( SvPV_nolen( get_sv("M6502::IPeriod", FALSE) ) );
20            // ICount IRequest IAutoReset TrapBadOps Trap Trace
21            dump_R;
22    }
23    
24    /** Rd6502()/Wr6502/Op6502() *********************************/
25    /** These functions are called when access to RAM occurs.   **/
26    /** They allow to control memory access. Op6502 is the same **/
27    /** as Rd6502, but used to read *opcodes* only, when many   **/
28    /** checks can be skipped to make it fast. It is only       **/
29    /** required if there is a #define FAST_RDOP.               **/
30    /************************************ TO BE WRITTEN BY USER **/
31    
32    byte Rd6502(register word Addr) {
33            byte Value;
34            Value = 0x42;
35            printf("Rd6502(%04x,%02x)\n", Addr, Value);
36    
37            int count;
38            dSP;
39            ENTER;
40            SAVETMPS;
41            PUSHMARK(SP);
42            XPUSHs( sv_2mortal( newSViv( Value ) ) );
43            PUTBACK;
44            count = call_pv("M6502::read", G_ARRAY );
45            if ( count != 1 ) {
46                    printf("expect 1 return value, got %d", count);
47                    exit(1);
48            }
49            printf("got %d values\n", count);
50            SPAGAIN;
51            SV *sv;
52            sv = POPs;
53            Value = SvIV(sv);
54    //      Value = savepv(SvPV_nolen(POPs));
55            FREETMPS;
56            LEAVE;
57            printf("Rd6502(%04x) = %02x\n", Addr, Value);
58            return Value;
59    }
60    
61    void Wr6502(register word Addr,register byte Value) {
62            printf("Wr6502(%04x,%02x)\n", Addr, Value);
63            dSP;
64            ENTER;
65            SAVETMPS;
66            PUSHMARK(SP);
67            XPUSHs( sv_2mortal( newSViv( Addr ) ) );
68            XPUSHs( sv_2mortal( newSViv( Value ) ) );
69            PUTBACK;
70            call_pv("M6502::write", G_DISCARD );
71            FREETMPS;
72            LEAVE;
73    }
74    
75    byte Op6502(register word Addr) {
76            byte Op;
77            Op = 0xff;
78            printf("Op6502(%04x,%02x)\n", Addr, Op);
79            dump_R;
80  }  }
81    
82    /** Loop6502() ***********************************************/
83    /** 6502 emulation calls this function periodically to      **/
84    /** check if the system hardware requires any interrupts.   **/
85    /** This function must return one of following values:      **/
86    /** INT_NONE, INT_IRQ, INT_NMI, or INT_QUIT to exit the     **/
87    /** emulation loop.                                         **/
88    /************************************ TO BE WRITTEN BY USER **/
89    byte Loop6502(register M6502 *R) {
90            printf("Loop6502\n");
91            dump_R;
92    }
93    
94    /** Patch6502() **********************************************/
95    /** Emulation calls this function when it encounters an     **/
96    /** unknown opcode. This can be used to patch the code to   **/
97    /** emulate BIOS calls, such as disk and tape access. The   **/
98    /** function should return 1 if the exception was handled,  **/
99    /** or 0 if the opcode was truly illegal.                   **/
100    /************************************ TO BE WRITTEN BY USER **/
101    byte Patch6502(register byte Op,register M6502 *R) {
102            printf("Patch6502(%02x)\n", Op);
103            dump_R;
104    }
105    
106    /**
107     * main code
108     *
109     **/
110    
111  int main(int argc, char **argv) {  int main(int argc, char **argv) {
112          char *command_line[] = {"", "-e",          char *command_line[] = {"", "-e",
113                  "use M6502; print \"Loaded M6502 module\n\";"};                  "use M6502; print \"Loaded M6502 module\n\";"};
# Line 31  int main(int argc, char **argv) { Line 127  int main(int argc, char **argv) {
127                          printf("can't alloc %d bytes for M6502", sizeof(M6502));                          printf("can't alloc %d bytes for M6502", sizeof(M6502));
128                          exit(1);                          exit(1);
129                  }                  }
130    
131                    update_R(R);
132    
133                  printf("reset CPU\n");                  printf("reset CPU\n");
134                  Reset6502(R);                  Reset6502(R);
135    
136                    printf("call M6502::init\n");
137                    dSP;
138                    PUSHMARK(SP);
139                    call_pv("M6502::init", G_DISCARD | G_NOARGS );
140    
141                    printf("run CPU\n");
142                    Run6502(R);
143    
144          }          }
145          free(R);          free(R);
146          perl_destruct(my_perl);          perl_destruct(my_perl);

Legend:
Removed from v.24  
changed lines
  Added in v.27

  ViewVC Help
Powered by ViewVC 1.1.26