# HG changeset patch # User Paul Boddie # Date 1323541226 -3600 # Node ID 0eb49bcc609b6981dc61a83dc53cab555cd22021 # Parent eee56889c57b8b9fec690af9f5c8bf77f17b39d4 Added an intermediate display buffer so that elementary Python data types can be used to test the core functionality, and so that Shedskin can compile the ula module and communicate with the graphical main program using such elementary types. diff -r eee56889c57b -r 0eb49bcc609b main.py --- a/main.py Fri Dec 09 01:45:40 2011 +0100 +++ b/main.py Sat Dec 10 19:20:26 2011 +0100 @@ -7,6 +7,9 @@ from ula import * import pygame +def update_surface(surface_array, screen_array): + surface_array[:] = screen_array + def mainloop(): while 1: pygame.display.flip() @@ -21,6 +24,7 @@ memory = get_memory() ula = ULA(memory) + ula_screen = get_screen() # Test MODE 2. @@ -28,11 +32,13 @@ fill(memory, 0x3000, 0x5800 - 320, encode((1, 6), 4)) fill(memory, 0x5800 - 320, 0x8000, encode((2, 7), 4)) - update(a, ula) + update(ula_screen, ula) + update_surface(a, ula_screen) mainloop() ula.screen_start = 0x3000 + 2 - update(a, ula) + update(ula_screen, ula) + update_surface(a, ula_screen) mainloop() # Test MODE 6. @@ -41,11 +47,13 @@ fill(memory, 0x6000, 0x6f00 + 160, encode((1, 0, 1, 1, 0, 0, 1, 1), 1)) fill(memory, 0x6f00 + 160, 0x7f40, encode((1, 0, 1, 0, 1, 0, 1, 0), 1)) - update(a, ula) + update(ula_screen, ula) + update_surface(a, ula_screen) mainloop() ula.screen_start = 0x6f00 + 160 - update(a, ula) + update(ula_screen, ula) + update_surface(a, ula_screen) mainloop() # vim: tabstop=4 expandtab shiftwidth=4 diff -r eee56889c57b -r 0eb49bcc609b ula.py --- a/ula.py Fri Dec 09 01:45:40 2011 +0100 +++ b/ula.py Sat Dec 10 19:20:26 2011 +0100 @@ -271,8 +271,27 @@ return result def get_memory(): + + "Return an array representing the computer's memory." + return array.array("B", itertools.repeat(0, MAX_MEMORY)) +def get_screen(): + + "Return a list of arrays representing the display." + + x = 0 + screen = [] + while x < WIDTH: + y = 0 + column = [] + while y < HEIGHT: + column.append((0, 0, 0)) + y += 1 + screen.append(column) + x += 1 + return screen + def fill(memory, start, end, value): for i in xrange(start, end): memory[i] = value @@ -289,11 +308,7 @@ # Make a simple two-dimensional array of tuples (three-dimensional in pygame # terminology). - a = [ - [(0, 0, 0), (0, 0, 0), (0, 0, 0)], - [(0, 0, 0), (0, 0, 0), (0, 0, 0)], - [(0, 0, 0), (0, 0, 0), (0, 0, 0)] - ] + a = get_screen() update(a, ula) # vim: tabstop=4 expandtab shiftwidth=4