/[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 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  void Reset6502(M6502 *R) {  #if 0
19          R->PC.W = atoi( SvPV_nolen( get_sv("M6502::PC", TRUE) ) );  #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          printf("PC: %04x\n", R->PC.W);  #else
21    #define dump_R
22    #endif
23    
24    void update_R(M6502 *R) {
25            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) ) );
29            R->X = atoi( SvPV_nolen( get_sv("M6502::X", FALSE) ) );
30            R->Y = atoi( SvPV_nolen( get_sv("M6502::Y", FALSE) ) );
31            R->S = atoi( SvPV_nolen( get_sv("M6502::S", FALSE) ) );
32            R->PC.W = atoi( SvPV_nolen( get_sv("M6502::PC", FALSE) ) );
33            R->IPeriod = atoi( SvPV_nolen( get_sv("M6502::IPeriod", FALSE) ) );
34            // ICount IRequest IAutoReset TrapBadOps Trap Trace
35            dump_R;
36    }
37    
38    /** Rd6502()/Wr6502/Op6502() *********************************/
39    /** These functions are called when access to RAM occurs.   **/
40    /** They allow to control memory access. Op6502 is the same **/
41    /** as Rd6502, but used to read *opcodes* only, when many   **/
42    /** checks can be skipped to make it fast. It is only       **/
43    /** required if there is a #define FAST_RDOP.               **/
44    /************************************ TO BE WRITTEN BY USER **/
45    
46    byte mem(word Addr) {
47            byte byte;
48            int count;
49            dSP;
50            ENTER;
51            SAVETMPS;
52            PUSHMARK(SP);
53            XPUSHs( sv_2mortal( newSViv( Addr ) ) );
54            PUTBACK;
55            count = call_pv("Arch::read", G_ARRAY );
56            if ( count != 1 ) {
57                    printf("expect 1 return value, got %d", count);
58                    exit(1);
59            }
60            //debugf(("got %d values\n", count));
61            SPAGAIN;
62            SV *sv;
63            sv = POPs;
64            byte = SvIV(sv);
65            FREETMPS;
66            LEAVE;
67            debugf(("Rd6502(%04x) = %02x\n", Addr, byte));
68            return byte;
69  }  }
70    
71    byte Rd6502(register word Addr) {
72            byte Value;
73            Value = mem(Addr);
74            return Value;
75    }
76    
77    void Wr6502(register word Addr,register byte Value) {
78            debugf(("Wr6502(%04x,%02x)\n", Addr, Value));
79            dSP;
80            ENTER;
81            SAVETMPS;
82            PUSHMARK(SP);
83            XPUSHs( sv_2mortal( newSViv( Addr ) ) );
84            XPUSHs( sv_2mortal( newSViv( Value ) ) );
85            PUTBACK;
86            call_pv("Arch::write", G_DISCARD );
87            FREETMPS;
88            LEAVE;
89    }
90    
91    byte Op6502(register word Addr) {
92            byte Op;
93            Op = mem(Addr);
94            debugf(("Op6502(%04x,%02x)\n", Addr, Op));
95            dump_R;
96    }
97    
98    /** Loop6502() ***********************************************/
99    /** 6502 emulation calls this function periodically to      **/
100    /** check if the system hardware requires any interrupts.   **/
101    /** This function must return one of following values:      **/
102    /** INT_NONE, INT_IRQ, INT_NMI, or INT_QUIT to exit the     **/
103    /** emulation loop.                                         **/
104    /************************************ TO BE WRITTEN BY USER **/
105    byte Loop6502(register M6502 *R) {
106            debugf(("Loop6502\n"));
107            dump_R;
108            return INT_NONE;
109    }
110    
111    /** Patch6502() **********************************************/
112    /** Emulation calls this function when it encounters an     **/
113    /** unknown opcode. This can be used to patch the code to   **/
114    /** emulate BIOS calls, such as disk and tape access. The   **/
115    /** function should return 1 if the exception was handled,  **/
116    /** or 0 if the opcode was truly illegal.                   **/
117    /************************************ TO BE WRITTEN BY USER **/
118    byte Patch6502(register byte Op,register M6502 *R) {
119            debugf(("Patch6502(%02x)\n", Op));
120            dump_R;
121            return 0;
122    }
123    
124    /**
125     * main code
126     *
127     **/
128    
129  int main(int argc, char **argv) {  int main(int argc, char **argv) {
130          char *command_line[] = {"", "-e",          char *command_line[] = {"", "-e", EMU_START };
                 "use M6502; print \"Loaded M6502 module\n\";"};  
131          my_perl = perl_alloc();          my_perl = perl_alloc();
132          perl_construct(my_perl);          perl_construct(my_perl);
133          if (perl_parse(my_perl, NULL, 3, command_line, (char **)NULL)) {          if (perl_parse(my_perl, xs_init, 3, command_line, (char **)NULL)) {
134                  printf("Failed to parse\n");                  printf("Failed to parse initial: %s\n", EMU_START );
135                  return 0;                  return 0;
136          }          }
137          perl_run(my_perl);          perl_run(my_perl);
# Line 31  int main(int argc, char **argv) { Line 144  int main(int argc, char **argv) {
144                          printf("can't alloc %d bytes for M6502", sizeof(M6502));                          printf("can't alloc %d bytes for M6502", sizeof(M6502));
145                          exit(1);                          exit(1);
146                  }                  }
147    
148                    update_R(R);
149    
150                  printf("reset CPU\n");                  printf("reset CPU\n");
151                  Reset6502(R);                  Reset6502(R);
152    
153                    printf("call Arch::init\n");
154                    dSP;
155                    PUSHMARK(SP);
156                    call_pv("Arch::init", G_DISCARD | G_NOARGS );
157    
158                    printf("run CPU\n");
159                    Run6502(R);
160    
161          }          }
162          free(R);          free(R);
163          perl_destruct(my_perl);          perl_destruct(my_perl);

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

  ViewVC Help
Powered by ViewVC 1.1.26