# HG changeset patch # User Paul Boddie # Date 1323384649 -3600 # Node ID 4f2eaf6a0ed3bd04f5f80e925a58e43d829d2c48 # Parent d99e8b32a95b072c34d7a42d0e9a5c717360174d Moved memory initialisation and the array and itertools imports to the ula module. Added a test program for the benefit of compilers like Shedskin. diff -r d99e8b32a95b -r 4f2eaf6a0ed3 main.py --- a/main.py Thu Dec 08 23:37:29 2011 +0100 +++ b/main.py Thu Dec 08 23:50:49 2011 +0100 @@ -6,8 +6,6 @@ from ula import * import pygame -import array -import itertools def mainloop(): while 1: @@ -19,10 +17,9 @@ if __name__ == "__main__": pygame.init() screen = pygame.display.set_mode((WIDTH, HEIGHT), 0) - - memory = array.array("B", itertools.repeat(0, MAX_MEMORY)) a = pygame.surfarray.pixels3d(screen) + memory = get_memory() ula = ULA(memory) # Test MODE 2. diff -r d99e8b32a95b -r 4f2eaf6a0ed3 ula.py --- a/ula.py Thu Dec 08 23:37:29 2011 +0100 +++ b/ula.py Thu Dec 08 23:50:49 2011 +0100 @@ -4,6 +4,9 @@ Acorn Electron ULA simulation. """ +import array +import itertools + WIDTH = 640 HEIGHT = 512 INTENSITY = 255 @@ -267,8 +270,30 @@ return result +def get_memory(): + return array.array("B", itertools.repeat(0, MAX_MEMORY)) + def fill(memory, start, end, value): for i in xrange(start, end): memory[i] = value +# Test program providing coverage (necessary for compilers like Shedskin). +# NOTE: Running this will actually cause an IndexError. + +if __name__ == "__main__": + memory = get_memory() + ula = ULA(memory) + ula.set_mode(2) + fill(memory, 0x5800 - 320, 0x8000, encode((2, 7), 4)) + + # 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)] + ] + update(a, ula) + # vim: tabstop=4 expandtab shiftwidth=4