[pypy-svn] r57732 - in pypy/dist/pypy/lang/gameboy: . test

tverwaes at codespeak.net tverwaes at codespeak.net
Mon Sep 1 17:11:36 CEST 2008


Author: tverwaes
Date: Mon Sep  1 17:11:35 2008
New Revision: 57732

Modified:
   pypy/dist/pypy/lang/gameboy/interrupt.py
   pypy/dist/pypy/lang/gameboy/joypad.py
   pypy/dist/pypy/lang/gameboy/serial.py
   pypy/dist/pypy/lang/gameboy/test/test_interrupt.py
   pypy/dist/pypy/lang/gameboy/test/test_joypad.py
   pypy/dist/pypy/lang/gameboy/test/test_serial.py
   pypy/dist/pypy/lang/gameboy/test/test_timer.py
   pypy/dist/pypy/lang/gameboy/timer.py
Log:
refactored constants.DEVICE to use direct links to InterruptFlag objects


Modified: pypy/dist/pypy/lang/gameboy/interrupt.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/interrupt.py	(original)
+++ pypy/dist/pypy/lang/gameboy/interrupt.py	Mon Sep  1 17:11:35 2008
@@ -61,7 +61,6 @@
     def __init__(self):
         self.create_interrupt_flags()
         self.create_flag_list()
-        self.create_flag_mask_mapping()
         self.reset()
         
     def create_interrupt_flags(self):
@@ -72,14 +71,12 @@
         self.joypad   = InterruptFlag(False, constants.JOYPAD, 0x60)
         
     def create_flag_list(self):
-        self.interrupt_flags = [ self.v_blank, self.lcd, self.timer, self.serial,
+        self.interrupt_flags = [ self.v_blank,
+                                 self.lcd,
+                                 self.timer,
+                                 self.serial,
                                  self.joypad]
 
-    def create_flag_mask_mapping(self):
-        self.mask_mapping = {}
-        for flag in self.interrupt_flags:
-            self.mask_mapping[flag.mask] = flag
-        
     def reset(self):
         self.set_enable_mask(0x0)
         for flag in self.interrupt_flags:
@@ -103,12 +100,6 @@
     def is_pending(self, mask=0xFF):
         return (self.get_enable_mask() & self.get_interrupt_flag() & mask) != 0
     
-    def raise_interrupt(self, mask):
-        self.mask_mapping[mask].set_pending()
-
-    def lower(self, mask):
-        self.mask_mapping[mask].set_pending(False)
-
     def get_enable_mask(self):
         enabled = 0x00
         for interrupt_flag in self.interrupt_flags:
@@ -118,7 +109,7 @@
 
     def set_enable_mask(self, enable_mask):
         for flag in self.interrupt_flags:
-            flag.set_enabled((enable_mask & flag.mask) != 0)
+            flag.set_enabled(bool(enable_mask & flag.mask))
         self.enable_rest_data = enable_mask & 0xE0;
         
     

Modified: pypy/dist/pypy/lang/gameboy/joypad.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/joypad.py	(original)
+++ pypy/dist/pypy/lang/gameboy/joypad.py	Mon Sep  1 17:11:35 2008
@@ -28,7 +28,7 @@
         assert isinstance(joypad_driver, JoypadDriver)
         assert isinstance(interrupt, Interrupt)
         self.driver    = joypad_driver
-        self.interrupt = interrupt
+        self.joypad_interrupt_flag = interrupt.joypad
         self.reset()
 
     def reset(self):
@@ -65,7 +65,7 @@
         elif self.read_control & 0x3 == 3:
             self.button_code  = 0xF
         if old_buttons != self.button_code:
-            self.interrupt.raise_interrupt(constants.JOYPAD)
+            self.joypad_interrupt_flag.set_pending()
 
 
 # ------------------------------------------------------------------------------
@@ -213,4 +213,4 @@
         self.pressed = True
         
     def is_pressed(self):
-        return self.pressed
\ No newline at end of file
+        return self.pressed

Modified: pypy/dist/pypy/lang/gameboy/serial.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/serial.py	(original)
+++ pypy/dist/pypy/lang/gameboy/serial.py	Mon Sep  1 17:11:35 2008
@@ -11,7 +11,7 @@
 
     def __init__(self, interrupt):
         assert isinstance(interrupt, Interrupt)
-        self.interrupt = interrupt
+        self.serial_interrupt_flag = interrupt.serial
         self.reset()
 
     def reset(self):
@@ -30,7 +30,7 @@
             self.serial_data     = 0xFF
             self.serial_control &= 0x7F
             self.cycles          = constants.SERIAL_IDLE_CLOCK
-            self.interrupt.raise_interrupt(constants.SERIAL)
+            self.serial_interrupt_flag.set_pending()
 
     def write(self, address, data):
         if address == constants.SERIAL_TRANSFER_DATA:
@@ -58,4 +58,4 @@
         return self.serial_data
 
     def get_serial_control(self):
-        return self.serial_control
\ No newline at end of file
+        return self.serial_control

Modified: pypy/dist/pypy/lang/gameboy/test/test_interrupt.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/test/test_interrupt.py	(original)
+++ pypy/dist/pypy/lang/gameboy/test/test_interrupt.py	Mon Sep  1 17:11:35 2008
@@ -54,19 +54,6 @@
         flag.set_pending(True)
         assert interrupt.is_pending(flag.mask)
     
-def test_raise_lower_interrupt():
-    interrupt = get_interrupt()
-    masks= [constants.LCD, constants.TIMER, 
-            constants.JOYPAD, constants.SERIAL]
-    interrupt.set_enable_mask(0xFF)
-    interrupt.v_blank.set_pending(True)
-    for mask in masks:
-        interrupt.raise_interrupt(mask)
-        assert interrupt.mask_mapping[mask].is_pending() == True
-        assert interrupt.is_pending(mask) == True
-        interrupt.lower(mask)
-        assert interrupt.is_pending(mask) == False
-    
 def test_read_write():
     interrupt = get_interrupt()
     interrupt.write(constants.IE, 0x12)

Modified: pypy/dist/pypy/lang/gameboy/test/test_joypad.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/test/test_joypad.py	(original)
+++ pypy/dist/pypy/lang/gameboy/test/test_joypad.py	Mon Sep  1 17:11:35 2008
@@ -263,7 +263,7 @@
     assert joypad.cycles      == constants.JOYPAD_CLOCK
     assert joypad.read_control == 2
     assert joypad.button_code == 0xF
-    assert joypad.interrupt.joypad.is_pending() == False
+    assert not joypad.joypad_interrupt_flag.is_pending()
     
     joypad.driver.raised      = True
     joypad.cycles             = 2
@@ -272,7 +272,7 @@
     assert joypad.cycles      == constants.JOYPAD_CLOCK
     assert joypad.read_control == 2
     assert joypad.button_code == constants.BUTTON_UP
-    assert joypad.interrupt.joypad.is_pending() == True
+    assert joypad.joypad_interrupt_flag.is_pending()
     
 def test_read_write():
     joypad = get_joypad()
@@ -308,13 +308,13 @@
     joypad.write(constants.JOYP, 0x10)
     joypad.update()
     assert joypad.button_code == constants.BUTTON_SELECT
-    assert joypad.interrupt.joypad.is_pending()
+    assert joypad.joypad_interrupt_flag.is_pending()
     
-    joypad.interrupt.joypad.set_pending(False)
+    joypad.joypad_interrupt_flag.set_pending(False)
     joypad.write(constants.JOYP, 0x10)
     joypad.update()
     assert joypad.button_code == constants.BUTTON_SELECT
-    assert joypad.interrupt.joypad.is_pending() ==  False
+    assert not joypad.joypad_interrupt_flag.is_pending()
     
     joypad.write(constants.JOYP, 0x20)
     joypad.update()
@@ -325,4 +325,4 @@
     assert joypad.button_code == 0xF
     
     
-    
\ No newline at end of file
+    

Modified: pypy/dist/pypy/lang/gameboy/test/test_serial.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/test/test_serial.py	(original)
+++ pypy/dist/pypy/lang/gameboy/test/test_serial.py	Mon Sep  1 17:11:35 2008
@@ -44,7 +44,7 @@
     assert cycles-serial.cycles                 == 2
     assert serial.serial_data                   == 0
     assert serial.serial_control                == 0x81
-    assert serial.interrupt.serial.is_pending() == False
+    assert not serial.serial_interrupt_flag.is_pending()
     
     serial.reset()
     serial.serial_control = 0x81
@@ -53,7 +53,7 @@
     assert serial.serial_data    == 0xFF
     assert serial.serial_control == 0x81 & 0x7F
     assert serial.cycles                        == constants.SERIAL_IDLE_CLOCK
-    assert serial.interrupt.serial.is_pending() == True
+    assert serial.serial_interrupt_flag.is_pending()
     
     
 def test_read_write():
@@ -69,4 +69,4 @@
     assert serial.serial_control                          == value
     
     assert serial.read(0) == 0xFF
-    
\ No newline at end of file
+    

Modified: pypy/dist/pypy/lang/gameboy/test/test_timer.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/test/test_timer.py	(original)
+++ pypy/dist/pypy/lang/gameboy/test/test_timer.py	Mon Sep  1 17:11:35 2008
@@ -216,12 +216,11 @@
     timer.timer_control = 0x04
     timer.timer_counter = -1
     # raise an interupt as we pass 0
-    assert timer.interrupt.is_pending(constants.TIMER) == False
-    assert timer.interrupt.timer.is_pending()          == False
+    assert not timer.timer_interrupt_flag.is_pending()
     timer.timer_cycles = -timer.timer_clock+1
     timer.emulate_timer(ticks)
     assert timer.timer_cycles  == 1
     assert timer.timer_counter == timer.timer_modulo
-    assert timer.interrupt.timer.is_pending()
+    assert timer.timer_interrupt_flag.is_pending()
+    
     
-    
\ No newline at end of file

Modified: pypy/dist/pypy/lang/gameboy/timer.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/timer.py	(original)
+++ pypy/dist/pypy/lang/gameboy/timer.py	Mon Sep  1 17:11:35 2008
@@ -23,7 +23,7 @@
 
     def __init__(self, interrupt):
         assert isinstance(interrupt, Interrupt)
-        self.interrupt = interrupt
+        self.timer_interrupt_flag = interrupt.timer
         self.reset()
 
     def reset(self):
@@ -145,7 +145,7 @@
         """
         if self.timer_counter == 0x00:
             self.timer_counter = self.timer_modulo
-            self.interrupt.raise_interrupt(constants.TIMER)
+            self.timer_interrupt_flag.set_pending()
     
     #def emulate_timer(self,  ticks):
     #    if (self.timer_control & 0x04) == 0:



More information about the Pypy-commit mailing list