/[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 195 by dpavlin, Sun Apr 13 00:32:39 2008 UTC revision 208 by dpavlin, Mon Apr 14 19:40:02 2008 UTC
# Line 11  M6502 *R = NULL; Line 11  M6502 *R = NULL;
11  int debug = 0;  int debug = 0;
12    
13  // same as memory size  // same as memory size
14  #define CACHE_SIZE 0xffff  #define CACHE_SIZE 0x10000
15  byte opCache[CACHE_SIZE];  byte memory[CACHE_SIZE];
16    
17  #define CALLBACK_READ_SKIP      0x00  #define CALLBACK_READ_SKIP      0x00
18  #define CALLBACK_READ_ONCE      0x01  #define CALLBACK_READ_ONCE      0x01
# Line 84  byte Debug6502(M6502 *R) { Line 84  byte Debug6502(M6502 *R) {
84  /************************************ TO BE WRITTEN BY USER **/  /************************************ TO BE WRITTEN BY USER **/
85    
86  byte mem(register word Addr) {  byte mem(register word Addr) {
87            debugf(("mem(%04x) callback %02x", Addr, perlCallBack[Addr]));
88    
89          if ( perlCallBack[Addr] & CALLBACK_READ_MASK == CALLBACK_READ_SKIP )          debugf(("### SKIP? %02x == %02x", perlCallBack[Addr] & CALLBACK_READ_MASK, CALLBACK_READ_SKIP));
90                  return opCache[Addr];          if ( ( perlCallBack[Addr] & CALLBACK_READ_MASK ) == CALLBACK_READ_SKIP ) {
91          if ( perlCallBack[Addr] & CALLBACK_READ_MASK == CALLBACK_READ_ONCE )                  debugf(("MEM: read callback skipped"));
92                    return memory[Addr];
93            }
94            if ( ( perlCallBack[Addr] & CALLBACK_READ_MASK ) == CALLBACK_READ_ONCE ) {
95                    debugf(("MEM: read callback disabled"));
96                  perlCallBack[Addr] = perlCallBack[Addr] & CALLBACK_WRITE_MASK | CALLBACK_READ_SKIP;                  perlCallBack[Addr] = perlCallBack[Addr] & CALLBACK_WRITE_MASK | CALLBACK_READ_SKIP;
97            }
98    
99          byte byte;          byte byte;
100          int count;          int count;
         debugf(("mem(%04x)", Addr));  
101          dSP;          dSP;
102          ENTER;          ENTER;
103          SAVETMPS;          SAVETMPS;
# Line 116  byte mem(register word Addr) { Line 121  byte mem(register word Addr) {
121          FREETMPS;          FREETMPS;
122          LEAVE;          LEAVE;
123          debugf(("mem(%04x) = %02x", Addr, byte));          debugf(("mem(%04x) = %02x", Addr, byte));
124          opCache[Addr] = byte;          memory[Addr] = byte;
125          return byte;          return byte;
126  }  }
127    
# Line 129  byte Rd6502(register word Addr) { Line 134  byte Rd6502(register word Addr) {
134    
135  void Wr6502(register word Addr,register byte Value) {  void Wr6502(register word Addr,register byte Value) {
136          debugf(("Wr6502(%04x,%02x)", Addr, Value));          debugf(("Wr6502(%04x,%02x)", Addr, Value));
137          opCache[Addr] = Value;          memory[Addr] = Value;
138          if ( perlCallBack[Addr] & CALLBACK_WRITE_MASK == CALLBACK_WRITE_SKIP ) return;          if ( ( perlCallBack[Addr] & CALLBACK_WRITE_MASK ) == CALLBACK_WRITE_SKIP ) {
139          if ( perlCallBack[Addr] & CALLBACK_WRITE_MASK == CALLBACK_WRITE_ONCE )                  debugf(("MEM: write callback skipped"));
140                    return;
141            }
142            if ( ( perlCallBack[Addr] & CALLBACK_WRITE_MASK ) == CALLBACK_WRITE_ONCE ) {
143                  perlCallBack[Addr] = perlCallBack[Addr] & CALLBACK_READ_MASK | CALLBACK_WRITE_SKIP;                  perlCallBack[Addr] = perlCallBack[Addr] & CALLBACK_READ_MASK | CALLBACK_WRITE_SKIP;
144                    debugf(("MEM: write callback skipped"));
145            }
146          dSP;          dSP;
147          ENTER;          ENTER;
148          SAVETMPS;          SAVETMPS;
# Line 194  reset (void) { Line 204  reset (void) {
204                          PerlIO_stdoutf("can't alloc %d bytes for M6502", sizeof(M6502));                          PerlIO_stdoutf("can't alloc %d bytes for M6502", sizeof(M6502));
205                          exit(1);                          exit(1);
206                  }                  }
207                  memset( opCache, 0, CACHE_SIZE );                  memset( memory, 0xff, CACHE_SIZE );
                 memset( perlCallBack, CALLBACK_READ_ALWAYS | CALLBACK_WRITE_ALWAYS, CACHE_SIZE );  
208          }          }
209            memset( perlCallBack, ( CALLBACK_READ_ALWAYS | CALLBACK_WRITE_ALWAYS ), CACHE_SIZE );
210          Reset6502(R);          Reset6502(R);
211          debugf(("Reset6502 over"));          debugf(("Reset6502 over"));
212          update_perl_R();          update_perl_R();
# Line 228  int get_debug(void) { Line 238  int get_debug(void) {
238    
239  /* FIXME somehow check if Addr will fit in int on current platform */  /* FIXME somehow check if Addr will fit in int on current platform */
240  void set_read_callback(int Addr) {  void set_read_callback(int Addr) {
241          perlCallBack[Addr] == perlCallBack[Addr] & CALLBACK_WRITE_MASK | CALLBACK_READ_ALWAYS;          perlCallBack[Addr] = perlCallBack[Addr] & CALLBACK_WRITE_MASK | CALLBACK_READ_ALWAYS;
242            debugf(("MEM: %04x read callback to %02x\n", Addr, perlCallBack[Addr]));
243  }  }
244    
245  void set_write_callback(int Addr) {  void set_write_callback(int Addr) {
246          perlCallBack[Addr] == perlCallBack[Addr] & CALLBACK_READ_MASK | CALLBACK_WRITE_ALWAYS;          perlCallBack[Addr] = perlCallBack[Addr] & CALLBACK_READ_MASK | CALLBACK_WRITE_ALWAYS;
247            debugf(("MEM: %04x write callback to %02x\n", Addr, perlCallBack[Addr]));
248  }  }
249    
250  /* we fake here, since we will need to call perl at least once to get initial value... */  /* we fake here, since we will need to call perl at least once to get initial value... */
251  int disable_all_callbacks(void) {  int set_all_callbacks(int mode) {
252          memset( perlCallBack, CALLBACK_READ_ONCE | CALLBACK_WRITE_ONCE, CACHE_SIZE );          memset( perlCallBack, mode, CACHE_SIZE );
253            debugf(("MEM: all callbacks set to %02x\n", perlCallBack[0]));
254          return perlCallBack[0];          return perlCallBack[0];
255  }  }
256    
257    int get_callback(int Addr) {
258            return perlCallBack[Addr];
259    }
260    
261    void mem_poke(int Addr, int byte) {
262            memory[Addr] = byte;
263    }
264    
265    int mem_peek(int Addr) {
266            return memory[Addr];
267    }
268    
269    
270  MODULE = M6502          PACKAGE = M6502  MODULE = M6502          PACKAGE = M6502
271    
272  PROTOTYPES: DISABLE  PROTOTYPES: DISABLE
273    
274  int  int set_debug(int state)
 set_debug(int state)  
275    
276  int  int get_debug()
 get_debug()  
277    
278  int  int reset()
 reset()  
279    
280  void  void update_C_R()
 update_C_R()  
281    
282  void  void update_perl_R()
 update_perl_R()  
283    
284  int  int exec(int cycles)
 exec(int cycles)  
285    
286  void  void set_read_callback(int Addr)
 set_read_callback(int Addr)  
287    
288  void  void set_write_callback(int Addr)
 set_write_callback(int Addr)  
289    
290  int  int set_all_callbacks(int mode)
291  disable_all_callbacks()  
292    int get_callback(int Addr)
293    
294    void mem_poke(int Addr, int byte)
295    
296    int mem_peek(int Addr)
297    
298    SV*
299    mem_peek_region(int from, int to)
300    CODE:  
301            RETVAL = newSVpvn(memory+from,to-from+1);
302    OUTPUT:
303            RETVAL
304    

Legend:
Removed from v.195  
changed lines
  Added in v.208

  ViewVC Help
Powered by ViewVC 1.1.26