/[VRac]/M6502/M6502.xs
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/M6502.xs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 91 by dpavlin, Thu Aug 2 12:37:06 2007 UTC revision 198 by dpavlin, Sun Apr 13 11:05:29 2008 UTC
# Line 10  Line 10 
10  M6502 *R = NULL;  M6502 *R = NULL;
11  int debug = 0;  int debug = 0;
12    
13    // same as memory size
14    #define CACHE_SIZE 0xffff
15    byte opCache[CACHE_SIZE];
16    
17    #define CALLBACK_READ_SKIP      0x00
18    #define CALLBACK_READ_ONCE      0x01
19    #define CALLBACK_READ_ALWAYS    0x02
20    #define CALLBACK_READ_MASK      0x0f
21    #define CALLBACK_WRITE_SKIP     0x00
22    #define CALLBACK_WRITE_ONCE     0x10
23    #define CALLBACK_WRITE_ALWAYS   0x20
24    #define CALLBACK_WRITE_MASK     0xf0
25    byte perlCallBack[CACHE_SIZE];
26    
27  void update_C_R(void) {  void update_C_R(void) {
28          R->A = SvIV( get_sv("M6502::A", FALSE) );          R->A = SvIV( get_sv("M6502::A", FALSE) );
29          R->P = SvIV( get_sv("M6502::P", FALSE) );          R->P = SvIV( get_sv("M6502::P", FALSE) );
# Line 69  byte Debug6502(M6502 *R) { Line 83  byte Debug6502(M6502 *R) {
83  /** required if there is a #define FAST_RDOP.               **/  /** required if there is a #define FAST_RDOP.               **/
84  /************************************ TO BE WRITTEN BY USER **/  /************************************ TO BE WRITTEN BY USER **/
85    
86  byte mem(word Addr) {  byte mem(register word Addr) {
87    
88            if ( perlCallBack[Addr] & CALLBACK_READ_MASK == CALLBACK_READ_SKIP )
89                    return opCache[Addr];
90            if ( perlCallBack[Addr] & CALLBACK_READ_MASK == CALLBACK_READ_ONCE )
91                    perlCallBack[Addr] = perlCallBack[Addr] & CALLBACK_WRITE_MASK | CALLBACK_READ_SKIP;
92    
93          byte byte;          byte byte;
94          int count;          int count;
95          debugf(("mem(%04x)", Addr));          debugf(("mem(%04x)", Addr));
# Line 96  byte mem(word Addr) { Line 116  byte mem(word Addr) {
116          FREETMPS;          FREETMPS;
117          LEAVE;          LEAVE;
118          debugf(("mem(%04x) = %02x", Addr, byte));          debugf(("mem(%04x) = %02x", Addr, byte));
119            opCache[Addr] = byte;
120          return byte;          return byte;
121  }  }
122    
123  byte Rd6502(register word Addr) {  byte Rd6502(register word Addr) {
124          byte Value;          byte Value;
125          Value = mem(Addr);          Value = mem(Addr);
 //      Value = 0x42;  
126          debugf(("Rd6502(%04x) = %02x", Addr, Value));          debugf(("Rd6502(%04x) = %02x", Addr, Value));
127          return Value;          return Value;
128  }  }
129    
130  void Wr6502(register word Addr,register byte Value) {  void Wr6502(register word Addr,register byte Value) {
131          debugf(("Wr6502(%04x,%02x)", Addr, Value));          debugf(("Wr6502(%04x,%02x)", Addr, Value));
132            if ( perlCallBack[Addr] & CALLBACK_WRITE_MASK == CALLBACK_WRITE_SKIP && opCache[Addr] == Value ) {
133                    debugf(("skipped perl callback, same value"));
134                    return;
135            }
136            opCache[Addr] = Value;
137            if ( perlCallBack[Addr] & CALLBACK_WRITE_MASK == CALLBACK_WRITE_SKIP ) return;
138            if ( perlCallBack[Addr] & CALLBACK_WRITE_MASK == CALLBACK_WRITE_ONCE )
139                    perlCallBack[Addr] = perlCallBack[Addr] & CALLBACK_READ_MASK | CALLBACK_WRITE_SKIP;
140          dSP;          dSP;
141          ENTER;          ENTER;
142          SAVETMPS;          SAVETMPS;
# Line 170  reset (void) { Line 198  reset (void) {
198                          PerlIO_stdoutf("can't alloc %d bytes for M6502", sizeof(M6502));                          PerlIO_stdoutf("can't alloc %d bytes for M6502", sizeof(M6502));
199                          exit(1);                          exit(1);
200                  }                  }
201                    memset( opCache, 0, CACHE_SIZE );
202                    memset( perlCallBack, CALLBACK_READ_ALWAYS | CALLBACK_WRITE_ALWAYS, CACHE_SIZE );
203          }          }
204          Reset6502(R);          Reset6502(R);
205          debugf(("Reset6502 over"));          debugf(("Reset6502 over"));
# Line 179  reset (void) { Line 209  reset (void) {
209  }  }
210    
211  int exec(int cycles) {  int exec(int cycles) {
212            int left;
213          debugf(("exec for %d cycles", cycles));          debugf(("exec for %d cycles", cycles));
214    
215          if (!R) reset();          if (!R) reset();
216    
217          update_C_R();          update_C_R();
218          Exec6502(R, cycles);          left = Exec6502(R, cycles);
219          update_perl_R();          update_perl_R();
220          debugf(("end of %d cycles CPU run\n", cycles));          debugf(("end of %d cycles CPU run\n", cycles));
221            return left;
222  }  }
223    
224  int set_debug(int state) {  int set_debug(int state) {
# Line 198  int get_debug(void) { Line 230  int get_debug(void) {
230          return debug;          return debug;
231  }  }
232    
233    /* FIXME somehow check if Addr will fit in int on current platform */
234    void set_read_callback(int Addr) {
235            perlCallBack[Addr] == perlCallBack[Addr] & CALLBACK_WRITE_MASK | CALLBACK_READ_ALWAYS;
236            debugf(("MEM: %04x read callback\n", Addr));
237    }
238    
239    void set_write_callback(int Addr) {
240            perlCallBack[Addr] == perlCallBack[Addr] & CALLBACK_READ_MASK | CALLBACK_WRITE_ALWAYS;
241            debugf(("MEM: %04x write callback\n", Addr));
242    }
243    
244    /* we fake here, since we will need to call perl at least once to get initial value... */
245    int set_all_callbacks(int mode) {
246            memset( perlCallBack, mode, CACHE_SIZE );
247            debugf(("MEM: all callbacks set to %02x\n", perlCallBack[0]));
248            return perlCallBack[0];
249    }
250    
251    int get_callback(int Addr) {
252            return perlCallBack[Addr];
253    }
254    
255    
256  MODULE = M6502          PACKAGE = M6502  MODULE = M6502          PACKAGE = M6502
257    
258  PROTOTYPES: DISABLE  PROTOTYPES: DISABLE
# Line 219  update_perl_R() Line 274  update_perl_R()
274    
275  int  int
276  exec(int cycles)  exec(int cycles)
277    
278    void
279    set_read_callback(int Addr)
280    
281    void
282    set_write_callback(int Addr)
283    
284    int
285    set_all_callbacks(int mode)
286    
287    int get_callback(int Addr)

Legend:
Removed from v.91  
changed lines
  Added in v.198

  ViewVC Help
Powered by ViewVC 1.1.26