1.1 --- a/main.py Sun Dec 11 01:11:35 2011 +0100
1.2 +++ b/main.py Mon Dec 12 01:31:51 2011 +0100
1.3 @@ -7,9 +7,32 @@
1.4 from ula import *
1.5 import pygame
1.6
1.7 -def update_surface(surface_array, screen_array):
1.8 - surface_array[:] = screen_array
1.9 - surface_array *= INTENSITY
1.10 +WIDTH = 640
1.11 +HEIGHT = 512
1.12 +INTENSITY = 255
1.13 +
1.14 +def update_screen(screen, screen_array):
1.15 +
1.16 + """
1.17 + Update the host's 'screen' surface with the contents of the 'screen_array'
1.18 + containing the pixel content of the screen.
1.19 + """
1.20 +
1.21 + surface = pygame.Surface((WIDTH, MAX_HEIGHT), 0, screen)
1.22 + a = pygame.surfarray.pixels3d(surface)
1.23 +
1.24 + # Copy the array to a surface and apply a pixel intensity.
1.25 +
1.26 + try:
1.27 + a[:] = screen_array
1.28 + a *= INTENSITY
1.29 + finally:
1.30 + del a
1.31 +
1.32 + # Scale the surface to the dimensions of the host's screen and copy the
1.33 + # result to the host's screen.
1.34 +
1.35 + screen.blit(pygame.transform.scale(surface, (WIDTH, HEIGHT)), (0, 0))
1.36
1.37 def mainloop():
1.38 while 1:
1.39 @@ -21,7 +44,6 @@
1.40 if __name__ == "__main__":
1.41 pygame.init()
1.42 screen = pygame.display.set_mode((WIDTH, HEIGHT), 0)
1.43 - a = pygame.surfarray.pixels3d(screen)
1.44
1.45 ula = get_ula()
1.46 ula_screen = get_screen()
1.47 @@ -33,12 +55,12 @@
1.48 ula.fill(0x3000, 0x5800 - 320, encode((1, 6), 4))
1.49 ula.fill(0x5800 - 320, 0x8000, encode((2, 7), 4))
1.50 update(ula_screen, ula)
1.51 - update_surface(a, ula_screen)
1.52 + update_screen(screen, ula_screen)
1.53 mainloop()
1.54
1.55 ula.screen_start = 0x3000 + 2
1.56 update(ula_screen, ula)
1.57 - update_surface(a, ula_screen)
1.58 + update_screen(screen, ula_screen)
1.59 mainloop()
1.60
1.61 # Test MODE 6.
1.62 @@ -48,12 +70,12 @@
1.63 ula.fill(0x6000, 0x6f00 + 160, encode((1, 0, 1, 1, 0, 0, 1, 1), 1))
1.64 ula.fill(0x6f00 + 160, 0x7f40, encode((1, 0, 1, 0, 1, 0, 1, 0), 1))
1.65 update(ula_screen, ula)
1.66 - update_surface(a, ula_screen)
1.67 + update_screen(screen, ula_screen)
1.68 mainloop()
1.69
1.70 ula.screen_start = 0x6f00 + 160
1.71 update(ula_screen, ula)
1.72 - update_surface(a, ula_screen)
1.73 + update_screen(screen, ula_screen)
1.74 mainloop()
1.75
1.76 # vim: tabstop=4 expandtab shiftwidth=4