ULA

Change of ula.py

29:2d6bb0876770
ula.py
     1.1 --- a/ula.py	Sun Dec 18 18:55:01 2011 +0100
     1.2 +++ b/ula.py	Sun Dec 18 19:29:20 2011 +0100
     1.3 @@ -4,6 +4,9 @@
     1.4  Acorn Electron ULA simulation.
     1.5  """
     1.6  
     1.7 +from array import array
     1.8 +from itertools import repeat
     1.9 +
    1.10  LINES_PER_ROW = 8       # the number of pixel lines per character row
    1.11  MAX_HEIGHT = 256        # the height of the screen in pixels
    1.12  MAX_SCANLINE = 312      # the number of scanlines in each frame
    1.13 @@ -13,26 +16,33 @@
    1.14  MAX_MEMORY = 0x10000    # the number of addressable memory locations
    1.15  BLANK = (0, 0, 0)
    1.16  
    1.17 -def update(screen, ula):
    1.18 +screen = array("B", repeat(0, MAX_WIDTH * 3 * MAX_HEIGHT))
    1.19 +
    1.20 +def update(ula):
    1.21  
    1.22      """
    1.23 -    Update the 'screen' array by reading from the 'ula'. This function
    1.24 -    effectively has the role of the video circuit, but also provides the clock
    1.25 -    signal to the ULA.
    1.26 +    Return a screen array by reading from the 'ula'. This function effectively
    1.27 +    has the role of the video circuit, but also provides the clock signal to the
    1.28 +    ULA.
    1.29      """
    1.30  
    1.31      ula.vsync()
    1.32 +    pos = 0
    1.33      y = 0
    1.34      while y < MAX_SCANLINE:
    1.35          x = 0
    1.36          while x < MAX_SCANPOS:
    1.37              colour = ula.get_pixel_colour()
    1.38              if x < MAX_WIDTH and y < MAX_HEIGHT:
    1.39 -                screen[x][y] = colour
    1.40 +                screen[pos] = colour[0]; pos += 1
    1.41 +                screen[pos] = colour[1]; pos += 1
    1.42 +                screen[pos] = colour[2]; pos += 1
    1.43              x += 1
    1.44          ula.hsync()
    1.45          y += 1
    1.46  
    1.47 +    return screen
    1.48 +
    1.49  class ULA:
    1.50  
    1.51      "The ULA functionality."
    1.52 @@ -276,17 +286,6 @@
    1.53  
    1.54      return [0] * MAX_MEMORY
    1.55  
    1.56 -def get_screen():
    1.57 -
    1.58 -    "Return a list of arrays representing the display."
    1.59 -
    1.60 -    x = 0
    1.61 -    screen = []
    1.62 -    while x < MAX_WIDTH:
    1.63 -        screen.append([(0, 0, 0)] * MAX_HEIGHT)
    1.64 -        x += 1
    1.65 -    return screen
    1.66 -
    1.67  def fill(memory, start, end, value):
    1.68      for i in xrange(start, end):
    1.69          memory[i] = value
    1.70 @@ -301,7 +300,6 @@
    1.71      # Make a simple two-dimensional array of tuples (three-dimensional in pygame
    1.72      # terminology).
    1.73  
    1.74 -    a = get_screen()
    1.75 -    update(a, ula)
    1.76 +    a = update(ula)
    1.77  
    1.78  # vim: tabstop=4 expandtab shiftwidth=4