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((MAX_WIDTH, MAX_HEIGHT), 0, screen) 22 sa = pygame.surfarray.pixels3d(surface) 23 a = sa.transpose(1, 0, 2) 24 25 # Copy the array to a surface and apply a pixel intensity. 26 27 try: 28 a.flat[:] = screen_array 29 a *= INTENSITY 30 finally: 31 del a, sa 32 33 # Scale the surface to the dimensions of the host's screen and copy the 34 # result to the host's screen. 35 36 screen.blit(pygame.transform.scale(surface, (WIDTH, HEIGHT)), (0, 0)) 37 38 def mainloop(): 39 while 1: 40 pygame.display.flip() 41 event = pygame.event.wait() 42 if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: 43 break 44 45 if __name__ == "__main__": 46 pygame.init() 47 screen = pygame.display.set_mode((WIDTH, HEIGHT), 0) 48 49 ula = get_ula() 50 51 # Test MODE 2. 52 53 ula.set_mode(2); ula.reset() 54 55 ula.ram.fill(0x3000, 0x5800 - 320, encode((1, 6), 4)) 56 ula.ram.fill(0x5800 - 320, 0x8000, encode((2, 7), 4)) 57 ula_screen = update(ula) 58 update_screen(screen, ula_screen) 59 print "Screen updated." 60 mainloop() 61 62 ula.screen_start = 0x3000 + 2 63 ula_screen = update(ula) 64 update_screen(screen, ula_screen) 65 print "Screen updated." 66 mainloop() 67 68 # Test MODE 6. 69 70 ula.set_mode(6); ula.reset() 71 72 ula.ram.fill(0x6000, 0x6f00 + 160, encode((1, 0, 1, 1, 0, 0, 1, 1), 1)) 73 ula.ram.fill(0x6f00 + 160, 0x7f40, encode((1, 0, 1, 0, 1, 0, 1, 0), 1)) 74 ula_screen = update(ula) 75 update_screen(screen, ula_screen) 76 print "Screen updated." 77 mainloop() 78 79 ula.screen_start = 0x6f00 + 160 80 ula_screen = update(ula) 81 update_screen(screen, ula_screen) 82 print "Screen updated." 83 mainloop() 84 85 # vim: tabstop=4 expandtab shiftwidth=4