[pypy-svn] r55397 - in pypy/dist/pypy/lang/gameboy: . test
cami at codespeak.net
cami at codespeak.net
Thu May 29 16:39:07 CEST 2008
Author: cami
Date: Thu May 29 16:39:06 2008
New Revision: 55397
Modified:
pypy/dist/pypy/lang/gameboy/cartridge.py
pypy/dist/pypy/lang/gameboy/test/test_memory_bank_controller.py
Log:
added clock test for the memory bank controller
fixed bug in the mbc3 clock_updat method which cause an endless loop
Modified: pypy/dist/pypy/lang/gameboy/cartridge.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/cartridge.py (original)
+++ pypy/dist/pypy/lang/gameboy/cartridge.py Thu May 29 16:39:06 2008
@@ -530,6 +530,7 @@
raise InvalidMemoryAccessException("MBC3.read_clock_data invalid address %i")
def write(self, address, data):
+ print hex(address), hex(data)
# 0000-1FFF
if address <= 0x1FFF:
self.write_ram_enable(address, data)
@@ -585,7 +586,7 @@
self.clock_latched_seconds = self.clock_seconds
self.clock_latched_minutes = self.clock_minutes
self.clock_latched_hours = self.clock_hours
- self.clock_latched_days = self.clock_days
+ self.clock_latched_days = self.clock_days & 0xFF
self.clock_latched_control = (self.clock_control & 0xFE) | \
((self.clock_days >> 8) & 0x01)
@@ -598,39 +599,22 @@
elapsed += self.clock_minutes * 60
elapsed += self.clock_seconds
- days = int(math.floor(elapsed / 24*60*60))
+ days = int(math.floor(elapsed / (24.0*60*60.0)))
self.clock_days += days
elapsed -= days * 24*60*60
- #while elapsed >= 246060:
- # elapsed -= 246060
- # self.clock_days+=1
-
- hours = int(math.floor(elapsed / 60*60))
+
+ hours = int(math.floor(elapsed / (60*60)))
self.clock_hours += hours
elapsed -= hours * 60*60
- #while elapsed >= 6060:
- # self.clock_hours+=1
- # elapsed -= 6060
minutes = int(math.floor(elapsed / 60))
self.clock_minutes += minutes
- elapsed -= hours * 60
- #while elapsed >= 60:
- # elapsed -= 60
- # self.clock_minutes+=1
+ elapsed -= minutes * 60
self.clock_seconds += elapsed
- #while self.clock_seconds >= 60:
- # self.clock_seconds -= 60
- # self.clock_minutes+=1
- #while self.clock_minutes >= 60:
- # self.clock_hours+=1
- # self.clock_minutes -= 60
- #while self.clock_hours >= 24:
- # self.clock_hours -= 24
- # self.clock_days+=1
- while self.clock_days >= 512:
- self.clock_days -= 512
+
+ if self.clock_days >= 512:
+ self.clock_days %= 512
self.clock_control |= 0x80
self.clock_time = now
@@ -806,21 +790,19 @@
now = self.clock.get_time()
elapsed = now - self.clock_time
# years (4 bits)
- while elapsed >= 365246060:
- self.clock_register += 1 << 24
- elapsed -= 365246060
+ years = int(math.floor(elapsed / (365*24*60*60)))
+ elapsed -= years*365*24*60*60
# days (12 bits)
- while elapsed >= 246060:
- self.clock_register += 1 << 12
- elapsed -= 246060
+ days = int(math.floor(elapsed / (24*60*60)))
+ elapsed -= days*24*60*60
# minutes (12 bits)
- while elapsed >= 60:
- self.clock_register += 1
- elapsed -= 60
- if (self.clock_register & 0x0000FFF) >= 2460:
- self.clock_register += (1 << 12) - 2460
- if (self.clock_register & 0x0FFF000) >= (365 << 12):
- self.clock_register += (1 << 24) - (365 << 12)
+ minutes = int(math.floor(elapsed / 60))
+ elapsed -= minutes*60
+
+ self.clock_register |= years << 24
+ self.clock_register |= days << 12
+ self.clock_register |= minutes
+
self.clock_time = now - elapsed
Modified: pypy/dist/pypy/lang/gameboy/test/test_memory_bank_controller.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/test/test_memory_bank_controller.py (original)
+++ pypy/dist/pypy/lang/gameboy/test/test_memory_bank_controller.py Thu May 29 16:39:06 2008
@@ -5,9 +5,18 @@
import py
import pdb
+class TestClock(object):
+ def __init__(self):
+ self.time = 0
+
+ def get_time(self):
+ return self.time
+
+
def get_clock_driver():
return Clock()
+
RAM_SIZE = 3
ROM_SIZE = 2
@@ -286,12 +295,13 @@
value %= 0x0F
# -----------------------------------------------------------------------------
-
+
def get_mbc3(rom_size=128, ram_size=4):
- return MBC3(get_rom(rom_size), get_ram(ram_size), get_clock_driver())
+ return MBC3(get_rom(rom_size), get_ram(ram_size), get_clock_driver())
+
+get_mbc3()
def test_mbc3_create():
- py.test.skip("takes too long")
mbc = get_mbc3()
fail_ini_test(mbc, 128, 0)
fail_ini_test(mbc, 128, 5)
@@ -300,11 +310,9 @@
basic_read_write_test(mbc, 0, 0x7FFF)
def test_mbc3_write_ram_enable():
- py.test.skip("takes too long")
write_ram_enable_test(get_mbc3())
def test_mbc3_write_rom_bank():
- py.test.skip("takes too long")
mbc= get_mbc3()
value = 1
for address in range(0x2000, 0x3FFF+1):
@@ -319,7 +327,6 @@
value %= 0xFF
def test_mbc3_write_ram_bank():
- py.test.skip("takes too long")
mbc = get_mbc3()
value = 1
for address in range(0x4000, 0x5FFF+1):
@@ -334,7 +341,6 @@
value %= 0xFF
def test_mbc3_write_clock_latch():
- py.test.skip("takes too long")
mbc = get_mbc3()
value = 1
for address in range(0x6000, 0x7FFF+1):
@@ -348,20 +354,17 @@
value %= 0xFF
def test_mbc3_read_write_ram():
- py.test.skip("takes too long")
mbc = get_mbc3()
value = 1
mbc.ram_enable = True
for address in range(0xA000, 0xBFFF+1):
mbc.write(address, value)
- #pdb.runcall(mbc.write, address, value)
assert mbc.ram[mbc.ram_bank + (address & 0x1FFF)] == value
assert mbc.read(address) == value;
value += 1
value %= 0xFF
def test_mbc3_read_write_clock():
- py.test.skip("takes too long")
mbc = get_mbc3()
value = 1
mbc.ram_enable = True
@@ -391,14 +394,70 @@
value += 1
value %= 0xFF
-
+
def test_mbc3_update_clock():
- py.test.skip("not yet implemented")
mbc = get_mbc3()
+ mbc.clock = TestClock()
+ mbc.clock.time = 1 + 2*60 + 3*60*60 + 4*24*60*60
+ mbc.clock_days = 0
+ mbc.clock_hours = 0
+ mbc.clock_minutes = 0
+ mbc.clock_seconds = 0
+ mbc.clock_time = 0
+ mbc.clock_control = 0xFF
+ mbc.update_clock()
+ assert mbc.clock_days == 0
+ assert mbc.clock_hours == 0
+ assert mbc.clock_minutes == 0
+ assert mbc.clock_seconds == 0
+ assert mbc.clock_time == mbc.clock.time
+
+ mbc.clock_time = 0
+ mbc.clock_control = 0x00
+ mbc.update_clock()
+ assert mbc.clock_days == 4
+ assert mbc.clock_hours == 3
+ assert mbc.clock_minutes == 2
+ assert mbc.clock_seconds == 1
+ assert mbc.clock_time == mbc.clock.time
+
+def test_mbc3_update_clock_day_overflow():
+ mbc = get_mbc3()
+ mbc.clock = TestClock()
+ mbc.clock.time = 2*512*24*60*60
+ mbc.clock_days = 0
+ mbc.clock_hours = 0
+ mbc.clock_minutes = 0
+ mbc.clock_seconds = 0
+ mbc.clock_time = 0
+ mbc.clock_control = 0x01
+ mbc.update_clock()
+ assert mbc.clock_days == 0
+ assert mbc.clock_hours == 0
+ assert mbc.clock_minutes == 0
+ assert mbc.clock_seconds == 0
+ assert mbc.clock_control == 0x81
def test_mbc3_latch_clock():
- py.test.skip("not yet implemented")
mbc = get_mbc3()
+ mbc.clock = TestClock()
+ mbc.clock.time = 1 + 2*60 + 3*60*60 + (0xFF+2)*24*60*60
+ mbc.clock_days = 0
+ mbc.clock_hours = 0
+ mbc.clock_minutes = 0
+ mbc.clock_seconds = 0
+ mbc.clock_time = 0
+ mbc.clock_control = 0x00
+ mbc.latch_clock()
+ assert mbc.clock_days == 0xFF+2
+ assert mbc.clock_latched_days == (0xFF+2) & 0xFF
+ assert mbc.clock_hours == 3
+ assert mbc.clock_latched_hours == 3
+ assert mbc.clock_minutes == 2
+ assert mbc.clock_latched_minutes == 2
+ assert mbc.clock_seconds == 1
+ assert mbc.clock_latched_seconds == 1
+ assert mbc.clock_latched_control == (mbc.clock_days>>8) & 0x01
# -----------------------------------------------------------------------------
@@ -559,7 +618,6 @@
value %= 0xFF
def test_huc3_write_clock_register_clock_shift():
- #py.test.skip("bug for in the clock")
mbc = get_huc3()
value = 1
mbc.ram_flag = 0x0B
@@ -593,10 +651,17 @@
value = +1
value %= 0xF
+
def test_huc3_update_clock():
- py.test.skip("not yet implemented")
mbc = get_huc3()
- pass
-
+ mbc.clock = TestClock()
+ mbc.clock.time = 1*60 + 2*24*60*60 + 3*365*24*60*60
+ mbc.clock_register = 0x00
+ mbc.clock_time = 0
+ mbc.update_clock()
+ assert mbc.clock_register & 0x00000FFF == 1
+ assert mbc.clock_register & 0x00FFF000 == 2 << 12
+ assert mbc.clock_register & 0xFF000000 == 3 << 24
+ assert mbc.clock_time == mbc.clock.time
# -----------------------------------------------------------------------------
More information about the Pypy-commit
mailing list