[pypy-svn] r57493 - in pypy/dist/pypy/lang/gameboy: . test
cami at codespeak.net
cami at codespeak.net
Wed Aug 20 09:45:06 CEST 2008
Author: cami
Date: Wed Aug 20 09:45:04 2008
New Revision: 57493
Modified:
pypy/dist/pypy/lang/gameboy/cartridge.py
pypy/dist/pypy/lang/gameboy/cpu.py
pypy/dist/pypy/lang/gameboy/gameboy.py
pypy/dist/pypy/lang/gameboy/gameboy_implementation.py
pypy/dist/pypy/lang/gameboy/test/test_memory_bank_controller.py
pypy/dist/pypy/lang/gameboy/test/test_video.py
pypy/dist/pypy/lang/gameboy/video.py
Log:
fixed bug in vide.set_line_y_compare, missed a check case
fixed bug in cartrdige.mbc1, params not correctly reset
adapted test cases for these bugs
Modified: pypy/dist/pypy/lang/gameboy/cartridge.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/cartridge.py (original)
+++ pypy/dist/pypy/lang/gameboy/cartridge.py Wed Aug 20 09:45:04 2008
@@ -16,7 +16,7 @@
# HELPERS ----------------------------------------------------------------------
-def has_cartridge_battery(self, cartridge_type):
+def has_cartridge_battery(cartridge_type):
return (cartridge_type == constants.TYPE_MBC1_RAM_BATTERY
or cartridge_type == constants.TYPE_MBC2_BATTERY
or cartridge_type == constants.TYPE_MBC3_RTC_BATTERY
@@ -67,7 +67,10 @@
# CARTRIDGE
class CartridgeManager(object):
-
+ """
+ Delegates the loading to the CartridgeFile,
+ verifies the Cartridge by calculating the checksums
+ """
def __init__(self, clock):
assert isinstance(clock, Clock)
self.clock = clock
@@ -188,7 +191,8 @@
class CartridgeFile(object):
"""
- File mapping. Holds the file contents
+ File mapping. Holds the file contents and is responsible for reading
+ and writing
"""
def __init__(self, file=None):
self.reset()
@@ -288,6 +292,7 @@
self.set_ram(ram)
def reset(self):
+ self.rom_bank = self.rom_bank_size
self.ram_bank = 0
self.ram_enable = False
self.rom_size = 0
Modified: pypy/dist/pypy/lang/gameboy/cpu.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/cpu.py (original)
+++ pypy/dist/pypy/lang/gameboy/cpu.py Wed Aug 20 09:45:04 2008
@@ -2,6 +2,7 @@
from pypy.lang.gameboy import constants
from pypy.lang.gameboy.ram import *
from pypy.lang.gameboy.interrupt import *
+import pdb
# ---------------------------------------------------------------------------
Modified: pypy/dist/pypy/lang/gameboy/gameboy.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/gameboy.py (original)
+++ pypy/dist/pypy/lang/gameboy/gameboy.py Wed Aug 20 09:45:04 2008
@@ -92,7 +92,7 @@
def emulate(self, ticks):
while ticks > 0:
count = self.get_cycles()
- #print "emulating", ticks, "cycles, available", count
+ print "python: ticks", count
self.cpu.emulate(count)
self.serial.emulate(count)
self.timer.emulate(count)
@@ -204,5 +204,5 @@
for tile in range(0, 12):
self.video.write(0x9904 + tile, tile + 1)
self.video.write(0x9924 + tile, tile + 13)
- self.video.write(0x9905 + 12, 25)
+ self.video.write(0x9904 + 12, 25)
Modified: pypy/dist/pypy/lang/gameboy/gameboy_implementation.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/gameboy_implementation.py (original)
+++ pypy/dist/pypy/lang/gameboy/gameboy_implementation.py Wed Aug 20 09:45:04 2008
@@ -10,6 +10,7 @@
from pypy.rlib.rsdl import RSDL, RSDL_helper
from pypy.rpython.lltypesystem import lltype, rffi
from pypy.rlib.objectmodel import specialize
+import time
# GAMEBOY ----------------------------------------------------------------------
@@ -36,7 +37,8 @@
isRunning = True
while isRunning and self.handle_events():
self.emulate(constants.GAMEBOY_CLOCK >> 2)
- RSDL.Delay(1)
+ time.sleep(10/1000)
+ RSDL.Delay(10)
except :
lltype.free(self.event, flavor='raw')
RSDL.Quit()
@@ -88,14 +90,15 @@
RSDL.Flip(self.screen)
def draw_pixels(self):
- #str = ""
+ pass
+ str = ""
for y in range(self.height):
- #str += "\n"
+ str += "\n"
for x in range(self.width):
- #if y%2 == 0 or True:
- # px = self.get_pixel_color(x, y)
- # str += ["#", "%", "+", " ", " "][px]
- RSDL_helper.set_pixel(self.screen, x, y, self.get_pixel_color(x, y))
+ if y%2 == 0 or True:
+ px = self.get_pixel_color(x, y)
+ str += ["#", "%", "+", " ", " "][px]
+ #RSDL_helper.set_pixel(self.screen, x, y, self.get_pixel_color(x, y))
#print str;
def pixel_map(self, x, y):
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 Wed Aug 20 09:45:04 2008
@@ -188,7 +188,7 @@
def test_mbc1_reset(mbc=None):
if mbc==None:
mbc = get_mbc1()
- mbc.rom_bank = constants.ROM_BANK_SIZE +1
+ mbc.rom_bank = 0
mbc.memory_model = 1
mbc.ram_enable = True
mbc.ram_bank = 1
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 Aug 20 09:45:04 2008
@@ -107,13 +107,28 @@
assert video.interrupt.lcd.is_pending() == False
video.control = 0x80
- video.line_y = value
+ video.line_y = 0xF6
+ video.stat = 0x04
+ video.write(0xFF45, value)
+ assert video.stat == 0x04
+ assert video.interrupt.lcd.is_pending() == False
+
+ video.control = 0x80
+ video.line_y = 0xF6
+ video.stat = 0x00
+ video.write(0xFF45, value)
+ assert video.stat == 0x04
+ assert video.interrupt.lcd.is_pending() == False
+
+ video.control = 0x80
+ video.line_y = 0xF6
video.stat = 0x40
video.write(0xFF45, value)
assert video.stat == 0x44
assert video.interrupt.lcd.is_pending() == True
+
def test_control():
video = get_video()
Modified: pypy/dist/pypy/lang/gameboy/video.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/video.py (original)
+++ pypy/dist/pypy/lang/gameboy/video.py Wed Aug 20 09:45:04 2008
@@ -6,7 +6,7 @@
from pypy.lang.gameboy import constants
from pypy.lang.gameboy.ram import iMemory
from pypy.lang.gameboy.cpu import process_2_complement
-
+import pdb
# -----------------------------------------------------------------------------
@@ -169,10 +169,13 @@
def write_oam(self, address, data):
if address >= constants.OAM_ADDR and \
address < (constants.OAM_ADDR + constants.OAM_SIZE):
- self.oam[address - constants.OAM_ADDR] = data & 0xFF
+ self.oam[address - constants.OAM_ADDR] = data & 0xFF
elif address >= constants.VRAM_ADDR and \
address < (constants.VRAM_ADDR + constants.VRAM_SIZE):
- self.vram[address - constants.VRAM_ADDR] = data & 0xFF
+ if (address - constants.VRAM_ADDR) == 0x1910 or \
+ (address - constants.VRAM_ADDR) == 0x1911:
+ pass
+ self.vram[address - constants.VRAM_ADDR] = data & 0xFF
def read(self, address):
address = int(address)
@@ -216,14 +219,17 @@
return self.cycles
def emulate(self, ticks):
+ print "python: video emulating"
ticks = int(ticks)
if (self.control & 0x80) != 0:
self.cycles -= ticks
self.consume_cycles()
+ print "python: video emulating DONE"
def consume_cycles(self):
while self.cycles <= 0:
mode = self.stat & 0x03
+ print mode
if mode == 0:
self.emulate_hblank()
elif mode == 1:
@@ -246,6 +252,7 @@
self.control = data
def reset_control(self, data):
+ print "python reset control"
# NOTE: do not reset constants.LY=LYC flag (bit 2) of the STAT register (Mr. Do!)
self.line_y = 0
self.stat = (self.stat & 0xFC)
@@ -261,6 +268,7 @@
return 0x80 | self.stat
def set_status(self, data):
+ print "python set_status"
self.stat = (self.stat & 0x87) | (data & 0x78)
self.set_status_bug()
@@ -293,7 +301,7 @@
self.line_y_compare = data
if (self.control & 0x80) == 0:
return
- self.emulate_hblank_line_y_compare()
+ self.emulate_hblank_line_y_compare(stat_check=True)
def get_dma(self):
return self.dma
@@ -372,38 +380,46 @@
# mode setting -----------------------------------------------------------
def set_mode_3_begin(self):
+ print "set_mode_3_begin"
self.stat = (self.stat & 0xFC) | 0x03
self.cycles += constants.MODE_3_BEGIN_TICKS
self.transfer = True
def set_mode_3_end(self):
+ print "set_mode_3_end"
self.stat = (self.stat & 0xFC) | 0x03
self.cycles += constants.MODE_3_END_TICKS
self.transfer = False
def set_mode_0(self):
+ print "set_mode_0"
self.stat = (self.stat & 0xFC)
self.cycles += constants.MODE_0_TICKS
self.h_blank_interrupt_check()
def set_mode_2(self):
+ print "set_mode_2"
self.stat = (self.stat & 0xFC) | 0x02
self.cycles += constants.MODE_2_TICKS
self.oam_interrupt_check()
def set_mode_1_begin(self):
+ print "set_mode_1_begin"
self.stat = (self.stat & 0xFC) | 0x01
self.cycles += constants.MODE_1_BEGIN_TICKS
def set_mode_1(self):
+ print "set_mode_1"
self.stat = (self.stat & 0xFC) | 0x01
self.cycles += constants.MODE_1_TICKS
def set_mode_1_between(self):
+ print "set_mode_1_between"
self.stat = (self.stat & 0xFC) | 0x01
self.cycles += constants.MODE_1_TICKS - constants.MODE_1_BEGIN_TICKS
def set_mode_1_end(self):
+ print "set_mode_1_end"
self.stat = (self.stat & 0xFC) | 0x01
self.cycles += constants.MODE_1_END_TICKS
@@ -417,9 +433,13 @@
else:
self.emulate_hblank_part_2()
- def emulate_hblank_line_y_compare(self):
+ def emulate_hblank_line_y_compare(self, stat_check=False):
if self.line_y == self.line_y_compare:
- self.line_y_line_y_compare_interrupt_check()
+ if stat_check:
+ if (self.stat & 0x04) == 0:
+ self.line_y_line_y_compare_interrupt_check()
+ else:
+ self.line_y_line_y_compare_interrupt_check()
else:
self.stat &= 0xFB
More information about the Pypy-commit
mailing list