1.1 --- a/main.py Sun Dec 18 18:55:01 2011 +0100
1.2 +++ b/main.py Sun Dec 18 19:29:20 2011 +0100
1.3 @@ -19,15 +19,16 @@
1.4 """
1.5
1.6 surface = pygame.Surface((MAX_WIDTH, MAX_HEIGHT), 0, screen)
1.7 - a = pygame.surfarray.pixels3d(surface)
1.8 + sa = pygame.surfarray.pixels3d(surface)
1.9 + a = sa.transpose(1, 0, 2)
1.10
1.11 # Copy the array to a surface and apply a pixel intensity.
1.12
1.13 try:
1.14 - a[:] = screen_array
1.15 + a.flat[:] = screen_array
1.16 a *= INTENSITY
1.17 finally:
1.18 - del a
1.19 + del a, sa
1.20
1.21 # Scale the surface to the dimensions of the host's screen and copy the
1.22 # result to the host's screen.
1.23 @@ -46,7 +47,6 @@
1.24 screen = pygame.display.set_mode((WIDTH, HEIGHT), 0)
1.25
1.26 ula = get_ula()
1.27 - ula_screen = get_screen()
1.28
1.29 # Test MODE 2.
1.30
1.31 @@ -54,12 +54,12 @@
1.32
1.33 ula.fill(0x3000, 0x5800 - 320, encode((1, 6), 4))
1.34 ula.fill(0x5800 - 320, 0x8000, encode((2, 7), 4))
1.35 - update(ula_screen, ula)
1.36 + ula_screen = update(ula)
1.37 update_screen(screen, ula_screen)
1.38 mainloop()
1.39
1.40 ula.screen_start = 0x3000 + 2
1.41 - update(ula_screen, ula)
1.42 + ula_screen = update(ula)
1.43 update_screen(screen, ula_screen)
1.44 mainloop()
1.45
1.46 @@ -69,12 +69,12 @@
1.47
1.48 ula.fill(0x6000, 0x6f00 + 160, encode((1, 0, 1, 1, 0, 0, 1, 1), 1))
1.49 ula.fill(0x6f00 + 160, 0x7f40, encode((1, 0, 1, 0, 1, 0, 1, 0), 1))
1.50 - update(ula_screen, ula)
1.51 + ula_screen = update(ula)
1.52 update_screen(screen, ula_screen)
1.53 mainloop()
1.54
1.55 ula.screen_start = 0x6f00 + 160
1.56 - update(ula_screen, ula)
1.57 + ula_screen = update(ula)
1.58 update_screen(screen, ula_screen)
1.59 mainloop()
1.60
2.1 --- a/ula.py Sun Dec 18 18:55:01 2011 +0100
2.2 +++ b/ula.py Sun Dec 18 19:29:20 2011 +0100
2.3 @@ -4,6 +4,9 @@
2.4 Acorn Electron ULA simulation.
2.5 """
2.6
2.7 +from array import array
2.8 +from itertools import repeat
2.9 +
2.10 LINES_PER_ROW = 8 # the number of pixel lines per character row
2.11 MAX_HEIGHT = 256 # the height of the screen in pixels
2.12 MAX_SCANLINE = 312 # the number of scanlines in each frame
2.13 @@ -13,26 +16,33 @@
2.14 MAX_MEMORY = 0x10000 # the number of addressable memory locations
2.15 BLANK = (0, 0, 0)
2.16
2.17 -def update(screen, ula):
2.18 +screen = array("B", repeat(0, MAX_WIDTH * 3 * MAX_HEIGHT))
2.19 +
2.20 +def update(ula):
2.21
2.22 """
2.23 - Update the 'screen' array by reading from the 'ula'. This function
2.24 - effectively has the role of the video circuit, but also provides the clock
2.25 - signal to the ULA.
2.26 + Return a screen array by reading from the 'ula'. This function effectively
2.27 + has the role of the video circuit, but also provides the clock signal to the
2.28 + ULA.
2.29 """
2.30
2.31 ula.vsync()
2.32 + pos = 0
2.33 y = 0
2.34 while y < MAX_SCANLINE:
2.35 x = 0
2.36 while x < MAX_SCANPOS:
2.37 colour = ula.get_pixel_colour()
2.38 if x < MAX_WIDTH and y < MAX_HEIGHT:
2.39 - screen[x][y] = colour
2.40 + screen[pos] = colour[0]; pos += 1
2.41 + screen[pos] = colour[1]; pos += 1
2.42 + screen[pos] = colour[2]; pos += 1
2.43 x += 1
2.44 ula.hsync()
2.45 y += 1
2.46
2.47 + return screen
2.48 +
2.49 class ULA:
2.50
2.51 "The ULA functionality."
2.52 @@ -276,17 +286,6 @@
2.53
2.54 return [0] * MAX_MEMORY
2.55
2.56 -def get_screen():
2.57 -
2.58 - "Return a list of arrays representing the display."
2.59 -
2.60 - x = 0
2.61 - screen = []
2.62 - while x < MAX_WIDTH:
2.63 - screen.append([(0, 0, 0)] * MAX_HEIGHT)
2.64 - x += 1
2.65 - return screen
2.66 -
2.67 def fill(memory, start, end, value):
2.68 for i in xrange(start, end):
2.69 memory[i] = value
2.70 @@ -301,7 +300,6 @@
2.71 # Make a simple two-dimensional array of tuples (three-dimensional in pygame
2.72 # terminology).
2.73
2.74 - a = get_screen()
2.75 - update(a, ula)
2.76 + a = update(ula)
2.77
2.78 # vim: tabstop=4 expandtab shiftwidth=4