1 #!/usr/bin/env python 2 3 """ 4 Acorn Electron ULA simulation controller. 5 """ 6 7 from ula import * 8 import pygame 9 10 WIDTH = 640 11 HEIGHT = 512 12 INTENSITY = 255 13 14 def update_screen(screen, screen_array): 15 16 """ 17 Update the host's 'screen' surface with the contents of the 'screen_array' 18 containing the pixel content of the screen. 19 """ 20 21 surface = pygame.Surface((WIDTH, MAX_HEIGHT), 0, screen) 22 a = pygame.surfarray.pixels3d(surface) 23 24 # Copy the array to a surface and apply a pixel intensity. 25 26 try: 27 a[:] = screen_array 28 a *= INTENSITY 29 finally: 30 del a 31 32 # Scale the surface to the dimensions of the host's screen and copy the 33 # result to the host's screen. 34 35 screen.blit(pygame.transform.scale(surface, (WIDTH, HEIGHT)), (0, 0)) 36 37 def mainloop(): 38 while 1: 39 pygame.display.flip() 40 event = pygame.event.wait() 41 if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: 42 break 43 44 if __name__ == "__main__": 45 pygame.init() 46 screen = pygame.display.set_mode((WIDTH, HEIGHT), 0) 47 48 ula = get_ula() 49 ula_screen = get_screen() 50 51 # Test MODE 2. 52 53 ula.set_mode(2) 54 55 ula.fill(0x3000, 0x5800 - 320, encode((1, 6), 4)) 56 ula.fill(0x5800 - 320, 0x8000, encode((2, 7), 4)) 57 update(ula_screen, ula) 58 update_screen(screen, ula_screen) 59 mainloop() 60 61 ula.screen_start = 0x3000 + 2 62 update(ula_screen, ula) 63 update_screen(screen, ula_screen) 64 mainloop() 65 66 # Test MODE 6. 67 68 ula.set_mode(6) 69 70 ula.fill(0x6000, 0x6f00 + 160, encode((1, 0, 1, 1, 0, 0, 1, 1), 1)) 71 ula.fill(0x6f00 + 160, 0x7f40, encode((1, 0, 1, 0, 1, 0, 1, 0), 1)) 72 update(ula_screen, ula) 73 update_screen(screen, ula_screen) 74 mainloop() 75 76 ula.screen_start = 0x6f00 + 160 77 update(ula_screen, ula) 78 update_screen(screen, ula_screen) 79 mainloop() 80 81 # vim: tabstop=4 expandtab shiftwidth=4