[pypy-svn] r57759 - in pypy/dist/pypy/lang/gameboy/profiling: . evaluation evaluation/logs

cami at codespeak.net cami at codespeak.net
Tue Sep 2 15:22:26 CEST 2008


Author: cami
Date: Tue Sep  2 15:22:25 2008
New Revision: 57759

Removed:
   pypy/dist/pypy/lang/gameboy/profiling/evaluation/logs/kirbysDreamland.txt
   pypy/dist/pypy/lang/gameboy/profiling/evaluation/logs/megaman.txt
   pypy/dist/pypy/lang/gameboy/profiling/evaluation/logs/rom9.txt
   pypy/dist/pypy/lang/gameboy/profiling/evaluation/logs/superMario.txt
Modified:
   pypy/dist/pypy/lang/gameboy/profiling/evaluation/evaluation_cpu.py
   pypy/dist/pypy/lang/gameboy/profiling/evaluation/evaluation_test_parser.py
   pypy/dist/pypy/lang/gameboy/profiling/evaluation/gameboy_evaluation_implementation.py
   pypy/dist/pypy/lang/gameboy/profiling/evaluation/gameboy_evaluation_target.py
   pypy/dist/pypy/lang/gameboy/profiling/profiling_cpu.py
Log:
fixed some bugs for the profiling version.
second order op codes are now executed correctly


Modified: pypy/dist/pypy/lang/gameboy/profiling/evaluation/evaluation_cpu.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/profiling/evaluation/evaluation_cpu.py	(original)
+++ pypy/dist/pypy/lang/gameboy/profiling/evaluation/evaluation_cpu.py	Tue Sep  2 15:22:25 2008
@@ -7,9 +7,9 @@
 class EvaluationCPU(CPU):
     
     
-    def __init__(self, interrupt, memory):
+    def __init__(self, interrupt, memory, cycleLimit):
         CPU.__init__(self, interrupt, memory)
-        self.cycle_limit = 0
+        self.cycle_limit = cycleLimit
         self.op_code_count           = 0
         self.fetch_exec_opcode_histo = [0]*(0xFF+1)
         self.opcode_histo            = [0]*(0xFF+1)
@@ -26,5 +26,5 @@
         debug.log(self.last_op_code)
         self.op_code_count += 1
         self.opcode_histo[self.last_op_code] += 1
-        #if self.op_code_count >= self.cycle_limit:
-        #    raise Exception("Maximal Cyclecount reached")
\ No newline at end of file
+        if self.op_code_count >= self.cycle_limit:
+            raise Exception("Maximal Cyclecount reached")
\ No newline at end of file

Modified: pypy/dist/pypy/lang/gameboy/profiling/evaluation/evaluation_test_parser.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/profiling/evaluation/evaluation_test_parser.py	(original)
+++ pypy/dist/pypy/lang/gameboy/profiling/evaluation/evaluation_test_parser.py	Tue Sep  2 15:22:25 2008
@@ -1,47 +1,39 @@
 #!/bin/python
 
-def add_rank(file):
-	lines = open(file).readlines()
-	lastRank = -1;
-	for line in lines[4:]:
-		pos = line.find(":")
-		try:
-			lastRank = int(line[:pos])
-			add_rank_opcodes(lastRank, line[pos+2:])
-		except :
-			add_rank_fetch_opcodes(lastRank, line[pos+2:])
-		
-			
-	
-def add_rank_opcodes(rank, opcodes):
-	opcodes = opcodes.strip().split(" ")
-	for opcode in opcodes:
-		op_codes[int(opcode, 16)] += rank
-	
-def add_rank_fetch_opcodes(rank, opcodes):
-	opcodes = opcodes.strip().split(" ")
-	for opcode in opcodes:
-		fetch_op_codes[int(opcode, 16)] += rank
+import operator
 
+def add_rank(file):
+    lines = open(file).readlines()
+    lastRank = -1;
+    for line in lines:
+        pos = line.find(":")
+        if pos > 0:
+            opcode = line[:pos].strip()
+            add_rank_opcode(line[:pos], int(line[pos+2:]))
+        
+            
+    
+def add_rank_opcode(opcode, count):
+    if not op_codes.has_key(opcode):
+        op_codes[opcode] = count
+    else:
+        op_codes[opcode] += count
+    
 
 def print_sorted(table):
-	dict = {}
-	for i in range(0xFF):
-		dict[table[i]] = i 
-	keys = dict.keys()
-	keys.sort()
-	for key in keys:
-		if key != 0:
-			print "0x%2x: %5i" % (dict[key], key)
-	
+    sorted_op_codes = sorted(op_codes.items(), key=operator.itemgetter(1))
+    sorted_op_codes.reverse()
+    for op_code in sorted_op_codes:
+        print "%9s : %s" % (op_code[0], op_code[1])
+    
 # --------------------------------------
 files = ["superMario.txt", "rom9.txt", "megaman.txt", "kirbysDreamland.txt"]
 
-op_codes = [0] * 0xFF
+op_codes = {}
 fetch_op_codes = [0] * 0xFF
 
 for file in files:
-	add_rank(file)
-	
+    add_rank("logs/"+file)
+    
 print_sorted(op_codes)
-	
\ No newline at end of file
+    
\ No newline at end of file

Modified: pypy/dist/pypy/lang/gameboy/profiling/evaluation/gameboy_evaluation_implementation.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/profiling/evaluation/gameboy_evaluation_implementation.py	(original)
+++ pypy/dist/pypy/lang/gameboy/profiling/evaluation/gameboy_evaluation_implementation.py	Tue Sep  2 15:22:25 2008
@@ -13,7 +13,7 @@
     def __init__(self, cycleLimit=0):
         GameBoyImplementation.__init__(self)
         self.cycleLimit = cycleLimit
-        self.cpu = EvaluationCPU(self.interrupt, self)
+        self.cpu = EvaluationCPU(self.interrupt, self, cycleLimit)
         self.cpu.cycle_limit = cycleLimit
     
     def handle_execution_error(self):

Modified: pypy/dist/pypy/lang/gameboy/profiling/evaluation/gameboy_evaluation_target.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/profiling/evaluation/gameboy_evaluation_target.py	(original)
+++ pypy/dist/pypy/lang/gameboy/profiling/evaluation/gameboy_evaluation_target.py	Tue Sep  2 15:22:25 2008
@@ -9,7 +9,7 @@
 
 
 debug.DEBUG_PRINT_LOGS = False
-ROM_PATH = str(py.magic.autopath().dirpath().dirpath())+"/rom"
+ROM_PATH = str(py.magic.autopath().dirpath().dirpath().dirpath())+"/rom"
 
 filename = ""
 if len(sys.argv) > 1:

Modified: pypy/dist/pypy/lang/gameboy/profiling/profiling_cpu.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/profiling/profiling_cpu.py	(original)
+++ pypy/dist/pypy/lang/gameboy/profiling/profiling_cpu.py	Tue Sep  2 15:22:25 2008
@@ -9,22 +9,23 @@
     
     def __init__(self, interrupt, memory):
         CPU.__init__(self, interrupt, memory)
-        self.cycle_limit = 0
-        self.op_code_count           = 0
-        self.fetch_exec_opcode_histo = [0]*(0xFF+1)
-        self.opcode_histo            = [0]*(0xFF+1)
-    
-    def fetch_execute(self):
-        CPU.fetch_execute(self)
-        self.op_code_count += 1
-        self.fetch_exec_opcode_histo[self.last_fetch_execute_op_code] += 1
-        debug.log(self.last_fetch_execute_op_code, is_fetch_execute=True)
+        self.op_codes = []
         
-    
-    def execute(self, opCode):
-        CPU.execute(self, opCode)
-        debug.log(self.last_op_code)
-        self.op_code_count += 1
-        self.opcode_histo[self.last_op_code] += 1
-        #if self.op_code_count >= self.cycle_limit:
-        #    raise Exception("Maximal Cyclecount reached")
\ No newline at end of file
+    def run(self, op_codes):
+        self.op_codes = op_codes
+        self.pc.set(0)
+        i = 0
+        while i < len(op_codes):
+            self.execute(op_codes[i])
+            i += 1
+            if op_codes[i] == 0xCB:
+                i += 1
+            self.pc.set(i) # 2 cycles
+        
+    def fetch(self, use_cycles=True):
+         # Fetching  1 cycle
+        if use_cycles:
+            self.cycles += 1
+        data =  self.op_codes[self.pc.get(use_cycles) % len(self.op_codes)];
+        self.pc.inc(use_cycles) # 2 cycles
+        return data
\ No newline at end of file



More information about the Pypy-commit mailing list