コード例 #1
0
def main(rom_file):
	pygame.init()
	#screen = pygame.display.set_mode((64, 64))
	video = Video()
	screen = pygame.display.set_mode(video.get_mode())
	#pygame.mouse.set_visible(0)
	pygame.display.update()
	
	surface = pygame.Surface(screen.get_size())
	surface = surface.convert()
	screen.blit(surface, (0, 0))
	video.set_surface(surface)
	
	pygame.display.flip()

	keyboard = Keyboard()
	computer = CPU(video)
	fd = open(rom_file, "rb")
	computer.load(fd.read())
	
	CLOCK_HZ = 10000 # 4194304
	TIMER_HZ = 30
	CPU_CLOCK_EVENT = USEREVENT + 1
	TIMER_CLOCK_EVENT = CPU_CLOCK_EVENT + 1

	#pygame.time.set_timer(CPU_CLOCK_EVENT, 1000 / CLOCK_HZ)
	#pygame.time.set_timer(TIMER_CLOCK_EVENT, int(1000 / TIMER_HZ))
	pygame.time.set_timer(TIMER_CLOCK_EVENT, 100)
	
	i = 0
	while True:

		event = pygame.event.poll()
		
		if event.type == pygame.QUIT:
			sys.exit()
		#elif event.type == CPU_CLOCK_EVENT:
		#	computer.tick()
		elif event.type == TIMER_CLOCK_EVENT:
			computer.timer()
		elif event.type == pygame.KEYUP:
			key = keyboard.translate(event.key)
			if not key is None: 
				computer.key_up(key)
		elif event.type == pygame.KEYDOWN:
			key = keyboard.translate(event.key)
			if not key is None: 
				computer.key_down(key)
				
		i += 1
		#print "timer " + str(i)
		computer.timer()
		computer.tick()
		#pygame.time.wait(1000 / CLOCK_HZ)
		
		screen.blit(surface, (0, 0))
		if not video.dirty_rect is None: 
			pygame.display.update(video.dirty_rect)

		video.dirty_rect = None
コード例 #2
0
    def test_init(self):
        self.assertEqual(cpu.MEMORY_SIZE, len(self.cpu.memory))
        self.assertEqual(bytearray(cpu.font_sprites),
                         self.cpu.memory[0:len(cpu.font_sprites)])
        self.assertEqual([], self.cpu.stack)
        self.assertEqual(0x200, self.cpu.pc)
        self.assertEqual(0x600,
                         CPU(Screen(), Keyboard(), starting_address=0x600).pc)
        self.assertEqual([0x00] * 16, self.cpu.V)
        self.assertEqual(0x000, self.cpu.I)
        self.assertEqual(0x000, self.cpu.I)
        self.assertEqual(0x00, self.cpu.delay_timer)
        self.assertEqual(0x00, self.cpu.sound_timer)

        self.assertEqual(0x042,
                         CPU(Screen(), Keyboard(), starting_address=0x042).pc)
コード例 #3
0
    def __init__(self, rom_file):
        signal.signal(signal.SIGINT, self.sigint_handler)

        self.commands = {
            "[di]sassemble": ("Disassemble: disassemble addr[, count=16]",
                              self.cmd_disassemble),
            "[r]egisters": ("Examine registers", self.cmd_registers),
            "[s]tep": ("One CPU step: step [count=1]", self.cmd_step),
            "[v]ideo": ("Examine video memory contents", self.cmd_video),
            "[du]mp": ("Dump memory: dump addr[, count=16]", self.cmd_dump),
            "[h]elp": ("This help", self.cmd_help),
            "[q]uit": ("Quit", self.cmd_quit),
        }

        self.video = Video()
        screen = pygame.display.set_mode(self.video.get_mode())
        #pygame.mouse.set_visible(0)
        pygame.display.update()

        surface = pygame.Surface(screen.get_size())
        surface = surface.convert()
        screen.blit(surface, (0, 0))
        self.video.set_surface(surface)

        pygame.display.flip()

        self.cpu = CPU(self.video)
        fd = open(rom_file, "rb")
        self.cpu.load(fd.read())
コード例 #4
0
ファイル: chip8.py プロジェクト: weibell/python-chip8-emu
    def __init__(self, scaling_factor: int, cycles_per_frame: int,
                 starting_address: int):
        pygame.init()
        self.screen = Screen(scaling_factor)
        self.keyboard = Keyboard()
        self.sound = Sound()
        self.cpu = CPU(self.screen, self.keyboard, starting_address)
        self.cycles_per_frame = cycles_per_frame

        sixty_hertz_ms = round(1000 / SIXTY_HERTZ)
        pygame.time.set_timer(SIXTY_HERTZ_CLOCK, sixty_hertz_ms)
        print(
            f"Target CPU speed: {cycles_per_frame * SIXTY_HERTZ} instructions per second"
        )
        print(f"Screen scaling factor: {scaling_factor}")
コード例 #5
0
ファイル: test_cpu.py プロジェクト: danaki/YaPyChip8
 def setUp(self):
     self.cpu = CPU()
コード例 #6
0
 def setUp(self):
     self.screen = Screen()
     self.keyboard = Keyboard()
     self.cpu = CPU(self.screen, self.keyboard)