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

cami at codespeak.net cami at codespeak.net
Wed May 28 11:34:05 CEST 2008


Author: cami
Date: Wed May 28 11:34:04 2008
New Revision: 55330

Modified:
   pypy/dist/pypy/lang/gameboy/interrupt.py
   pypy/dist/pypy/lang/gameboy/test/test_cpu.py
   pypy/dist/pypy/lang/gameboy/test/test_interrupt.py
   pypy/dist/pypy/lang/gameboy/test/test_video.py
   pypy/dist/pypy/lang/gameboy/video.py
Log:
added more tests for video
renamed v_blank to vblank in all files


Modified: pypy/dist/pypy/lang/gameboy/interrupt.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/interrupt.py	(original)
+++ pypy/dist/pypy/lang/gameboy/interrupt.py	Wed May 28 11:34:04 2008
@@ -34,7 +34,7 @@
         self.reset()
         
     def create_interrupt_flags(self):
-        self.v_blank = InterruptFlag(True, constants.VBLANK, 0x40)
+        self.vblank = InterruptFlag(True, constants.VBLANK, 0x40)
         self.lcd     = InterruptFlag(False, constants.LCD, 0x48)
         self.timer   = InterruptFlag(False, constants.TIMER, 0x50)
         self.serial  = InterruptFlag(False, constants.SERIAL, 0x58)
@@ -42,7 +42,7 @@
         
     def create_flag_list(self):
         self.interrupt_flags = [
-            self.v_blank, self.lcd, 
+            self.vblank, self.lcd, 
             self.timer, self.serial,
             self.joypad
         ]
@@ -61,8 +61,8 @@
         if not self.enable:
             return False
         if mask is None:
-            return self.v_blank.is_pending()
-        elif self.v_blank.is_pending():
+            return self.vblank.is_pending()
+        elif self.vblank.is_pending():
             return self.mask_mapping[mask].is_pending()
         else:
             return False
@@ -74,14 +74,12 @@
         self.mask_mapping[mask].set_pending(False)
 
     def write(self, address, data):
-        address = int(address)
         if  address == constants.IE:
             self.set_interrupt_enable(data)
         elif address == constants.IF:
             self.set_fnterrupt_flag(data)
 
     def read(self, address):
-        address = int(address)
         if  address == constants.IE:
             return self.get_interrupt_enable()
         elif address == constants.IF:

Modified: pypy/dist/pypy/lang/gameboy/test/test_cpu.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/test/test_cpu.py	(original)
+++ pypy/dist/pypy/lang/gameboy/test/test_cpu.py	Wed May 28 11:34:04 2008
@@ -1276,7 +1276,7 @@
     cpu.reset()
     cpu.halted = True
     cpu.interrupt.set_interrupt_enable()
-    cpu.interrupt.v_blank.set_pending()
+    cpu.interrupt.vblank.set_pending()
     assert cpu.interrupt.is_pending() == True
     cpu.cycles = 4
     cpu.handle_pending_interrupt()
@@ -1290,14 +1290,14 @@
     cpu.sp.set(0x02)
     sp = cpu.sp.get()
     cpu.interrupt.set_interrupt_enable()
-    cpu.interrupt.v_blank.set_pending()
+    cpu.interrupt.vblank.set_pending()
     cpu.interrupt.lcd.set_pending()
     assert cpu.interrupt.is_pending() == True
     cpu.cycles = 0
     cpu.handle_pending_interrupt()
     assert cpu.cycles == 0
     assert cpu.halted == False 
-    assert_default_registers(cpu, pc=cpu.interrupt.v_blank.call_code, sp=sp-2)
+    assert_default_registers(cpu, pc=cpu.interrupt.vblank.call_code, sp=sp-2)
     assert cpu.pop() == 0x34
     assert cpu.pop() == 0x12
 
@@ -1391,7 +1391,7 @@
     cpu.ime = True
     cpu.halted = False
     prepare_for_fetch(cpu, 0x00)  # nop 1 cycle
-    cpu.interrupt.v_blank.set_pending()
+    cpu.interrupt.vblank.set_pending()
     cpu.interrupt.serial.set_pending()
     cpu.interrupt.set_interrupt_enable(True)
     assert cpu.interrupt.is_pending() == True
@@ -1399,8 +1399,8 @@
     assert cpu.ime == True  
     cycle_test(cpu, 0xFB, 1+1)
     assert cpu.interrupt.is_pending() == False
-    assert cpu.interrupt.v_blank.is_pending() == False
-    assert cpu.pc.get() == cpu.interrupt.v_blank.call_code
+    assert cpu.interrupt.vblank.is_pending() == False
+    assert cpu.pc.get() == cpu.interrupt.vblank.call_code
     assert cpu.ime == False
 
 def conditionalCallTest(cpu, opCode, flagSetter):

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	Wed May 28 11:34:04 2008
@@ -31,7 +31,7 @@
     for flag in interrupt.interrupt_flags:
         interrupt.reset()
         interrupt.enable = True
-        assert interrupt.v_blank.is_pending()
+        assert interrupt.vblank.is_pending()
         flag.set_pending(True)
         assert interrupt.is_pending(flag.mask)
         
@@ -41,7 +41,7 @@
     masks= [constants.LCD, constants.TIMER, 
             constants.JOYPAD, constants.SERIAL]
     interrupt.set_interrupt_enable(True)
-    interrupt.v_blank.set_pending(True)
+    interrupt.vblank.set_pending(True)
     for mask in masks:
         interrupt.raise_interrupt(mask)
         assert interrupt.mask_mapping[mask].is_pending() == True

Modified: pypy/dist/pypy/lang/gameboy/test/test_video.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/test/test_video.py	(original)
+++ pypy/dist/pypy/lang/gameboy/test/test_video.py	Wed May 28 11:34:04 2008
@@ -241,38 +241,119 @@
     video.line_y_compare = 1
     video.stat = 0x20
     video.cycles = 0
+    video.frames = 0
     assert not video.interrupt.lcd.is_pending()
     video.emulate_hblank()
     assert video.cycles == constants.MODE_2_TICKS
     assert video.interrupt.lcd.is_pending()
     assert video.stat == 0x20 + 0x04 + 0x2
+    assert video.line_y == 1
+    assert video.frames == 0
     
     
 def test_emulate_h_blank_part_2_1():
-    py.test.skip("not yet implemented")
     video = get_video()
     video.line_y = 1
-    video.line_y_compare = 1
-    video.stat = 0x20
+    video.line_y_compare = 0
+    video.stat = 0x0F
     video.cycles = 0
-    assert not video.interrupt.lcd.is_pending()
+    video.frames = 0
     video.emulate_hblank()
+    assert video.line_y == 2
     assert video.cycles == constants.MODE_2_TICKS
-    assert video.interrupt.lcd.is_pending()
-    assert video.stat == 0x20 + 0x04 + 0x2
-    
+    assert not video.interrupt.lcd.is_pending()
+    assert video.stat == 0x0B&0xFC + 0x2
+    assert video.frames == 0
     
-def test_emulate_h_blank_part_1_2():
-    py.test.skip("not yet implemented")
+def test_emulate_h_blank_part_2_2():
     video = get_video()
-    video.line_y = 1
-    video.line_y_compare = 1
-    video.stat = 0x20
+    video.line_y = 144
+    video.line_y_compare = 0
+    video.stat = 0xFB
     video.cycles = 0
+    video.frames = 0
+    video.frame_skip = 20
+    video.vblank = False
+    video.display = False
+    video.emulate_hblank()
+    assert video.line_y == 145
+    assert video.cycles == constants.MODE_1_BEGIN_TICKS
     assert not video.interrupt.lcd.is_pending()
+    assert video.stat == 0xFB & 0xFC + 0x01
+    assert video.frames == 1
+    assert video.display == False
+    assert video.vblank == True
+    
+
+def test_emulate_h_blank_part_2_2_frame_skip():
+    video = get_video()
+    video.line_y = 144
+    video.line_y_compare = 0
+    video.stat = 0xFB
+    video.cycles = 0
+    video.frames = 10
+    video.frame_skip = 10
+    video.vblank = False
+    video.display = False
     video.emulate_hblank()
-    assert video.cycles == constants.MODE_2_TICKS
+    assert video.line_y == 145
+    assert video.cycles == constants.MODE_1_BEGIN_TICKS
+    assert not video.interrupt.lcd.is_pending()
+    assert video.stat == 0xFB & 0xFC + 0x01
+    assert video.frames == 0
+    assert video.vblank == True
+    
+    
+def test_emulate_v_vblank_1():
+    video = get_video()   
+    video.interrupt.set_fnterrupt_flag(0)
+    video.stat = 0xFE
+    video.vblank = True
+    video.cycles = 0
+    video.emulate_vblank()
+    assert video.vblank == False
+    assert video.stat == 0xFD
+    assert video.cycles == constants.MODE_1_TICKS - constants.MODE_1_BEGIN_TICKS
+    assert video.interrupt.vblank.is_pending()
     assert video.interrupt.lcd.is_pending()
-    assert video.stat == 0x20 + 0x04 + 0x2
+    
+    video.interrupt.set_fnterrupt_flag(0)
+    video.stat = 0x00
+    video.vblank = True
+    assert not video.interrupt.vblank.is_pending()
+    assert not video.interrupt.lcd.is_pending()
+    video.emulate_vblank()
+    assert video.stat == 0x01
+    assert video.interrupt.vblank.is_pending()
+    assert not video.interrupt.lcd.is_pending()
+    
+    
+    
+def test_emulate_v_vblank_2():
+    video = get_video()   
+    video.interrupt.set_fnterrupt_flag(0)
+    video.stat = 0x2D
+    video.vblank = False
+    video.cycles = 0
+    video.line_y = 0
+    video.emulate_vblank()
+    assert video.vblank == False
+    assert video.stat == 0x2E
+    assert video.cycles == constants.MODE_2_TICKS 
+    assert not video.interrupt.vblank.is_pending()
+    assert video.interrupt.lcd.is_pending()
+    
+    video.interrupt.set_fnterrupt_flag(0)
+    video.cycles = 0
+    video.stat = 0xFD
+    video.emulate_vblank()
+    assert video.vblank == False
+    assert video.stat == 0xFE
+    assert video.cycles == constants.MODE_2_TICKS 
+    assert not video.interrupt.lcd.is_pending()
+    
+
+def test_emulate_v_vblank_3():
+    py.test.skip("not yet implemented")
     
     
\ No newline at end of file

Modified: pypy/dist/pypy/lang/gameboy/video.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/video.py	(original)
+++ pypy/dist/pypy/lang/gameboy/video.py	Wed May 28 11:34:04 2008
@@ -43,7 +43,7 @@
         self.h_blank_interrupt  = False
         self.oam_interrupt      = False
         self.h_blank_interrupt  = False
-        self.v_blank_interrupt  = False
+        self.vblank_interrupt  = False
         #Coincidence Flag  (0:LYC<>LY, 1:LYC=LY)
         self.coincidence_flag   = False
         
@@ -53,7 +53,7 @@
         value += int(self.h_blank_interrupt)  << 6 
         value += int(self.oam_interrupt)      << 5
         value += int(self.h_blank_interrupt)  << 4
-        value += int(self.v_blank_interrupt)  << 3
+        value += int(self.vblank_interrupt)  << 3
         value += int(self.coincidence_flag)   << 2
         value += self.mode & 0x03
         return value



More information about the Pypy-commit mailing list