/[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 108 by dpavlin, Fri Aug 3 09:18:08 2007 UTC revision 197 by dpavlin, Sun Apr 13 00:44:30 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];  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 71  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 111  byte Rd6502(register word Addr) { Line 129  byte Rd6502(register word Addr) {
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;          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 126  void Wr6502(register word Addr,register Line 151  void Wr6502(register word Addr,register
151    
152  byte Op6502(register word Addr) {  byte Op6502(register word Addr) {
153          byte Op;          byte Op;
         if ( opCache[Addr] ) return opCache[Addr];  
154          Op = mem(Addr);          Op = mem(Addr);
155          debugf(("Op6502(%04x,%02x) PC:%04x", Addr, Op, R->PC.W));          debugf(("Op6502(%04x,%02x) PC:%04x", Addr, Op, R->PC.W));
156          return Op;          return Op;
# Line 174  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, sizeof(opCache) );                  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 205  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    }
237    
238    void set_write_callback(int Addr) {
239            perlCallBack[Addr] == perlCallBack[Addr] & CALLBACK_READ_MASK | CALLBACK_WRITE_ALWAYS;
240    }
241    
242    /* we fake here, since we will need to call perl at least once to get initial value... */
243    int disable_all_callbacks(void) {
244            memset( perlCallBack, CALLBACK_READ_ONCE | CALLBACK_WRITE_ONCE, CACHE_SIZE );
245            return perlCallBack[0];
246    }
247    
248    
249  MODULE = M6502          PACKAGE = M6502  MODULE = M6502          PACKAGE = M6502
250    
251  PROTOTYPES: DISABLE  PROTOTYPES: DISABLE
# Line 226  update_perl_R() Line 267  update_perl_R()
267    
268  int  int
269  exec(int cycles)  exec(int cycles)
270    
271    void
272    set_read_callback(int Addr)
273    
274    void
275    set_write_callback(int Addr)
276    
277    int
278    disable_all_callbacks()
279    

Legend:
Removed from v.108  
changed lines
  Added in v.197

  ViewVC Help
Powered by ViewVC 1.1.26