File tree Expand file tree Collapse file tree 4 files changed +55
-0
lines changed Expand file tree Collapse file tree 4 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,14 @@ export class Processor {
5858 this . reset ( ) ; 
5959 } 
6060
61+  public  setPC ( pc : number )  { 
62+  this . bigRegisters [ PC ]  =  pc ; 
63+  } 
64+ 
65+  public  getPC ( )  { 
66+  return  this . bigRegisters [ PC ] ; 
67+  } 
68+ 
6169 public  reset ( )  { 
6270 // set the PC to the reset vector 
6371 this . registers  =  new  Uint8Array ( 5 ) ; 
Original file line number Diff line number Diff line change 1+ You will need 6502_functional_test.bin taken from (or compiled from) Klaus's test suite: https://github.com/Klaus2m5/6502_65C02_functional_tests/tree/master 
Original file line number Diff line number Diff line change 1+ import  {  Addressable  }  from  "../Addressable" ; 
2+ 
3+ export  class  TestRam  implements  Addressable  { 
4+  private  data : Uint8Array ; 
5+ 
6+  constructor ( data : Uint8Array )  { 
7+  this . data  =  data ; 
8+  } 
9+ 
10+  public  read ( location : number ) : number  { 
11+  return  this . data [ location ] ; 
12+  } 
13+ 
14+  public  write ( location : number ,  data : number )  { 
15+  this . data [ location ]  =  data ; 
16+  } 
17+ } 
Original file line number Diff line number Diff line change 1+ import  {  Processor  }  from  "../Processor" ; 
2+ import  {  readFileSync  }  from  "fs" ; 
3+ import  {  TestRam  }  from  "./TestRam" ; 
4+ 
5+ const  ramData  =  readFileSync ( "./6502_functional_test.bin" ) ; 
6+ const  ram  =  new  TestRam ( ramData ) ; 
7+ 
8+ const  processor  =  new  Processor ( ram ) ; 
9+ processor . setPC ( 0x0400 ) ; 
10+ 
11+ const  startTime  =  Date . now ( ) ; 
12+ let  cyclesSinceStart  =  0 ; 
13+ let  hz  =  1000000 ; 
14+ const  interval  =  setInterval ( ( )  =>  { 
15+  const  secondsElapsed  =  ( Date . now ( )  -  startTime )  /  1000 ; 
16+  const  totalExpectedCycles  =  secondsElapsed  *  hz ; 
17+  while  ( cyclesSinceStart  <  totalExpectedCycles )  { 
18+  const  pcBefore  =  processor . getPC ( ) ; 
19+  cyclesSinceStart  +=  processor . tick ( true ) ; 
20+  if  ( processor . getPC ( )  ===  pcBefore )  { 
21+  console . log ( "TRAPPED" ) ; 
22+  const  stack  =  ramData . subarray ( 0x100 ,  0x200 ) ; 
23+  console . log ( stack . toString ( "hex" ) . match ( / ../ g) ?. join ( " " ) ) ; 
24+  process . exit ( ) ; 
25+  } 
26+  } 
27+ } ,  1 ) ; 
28+ 
29+ process . on ( "beforeExit" ,  ( )  =>  { } ) ; 
                         You can’t perform that action at this time. 
           
                  
0 commit comments