1 #!/usr/bin/env python 2 3 """ 4 Acorn Electron ULA simulation controller. 5 6 Copyright (C) 2011, 2012, 2013, 2014 Paul Boddie <paul@boddie.org.uk> 7 8 This program is free software; you can redistribute it and/or modify it under 9 the terms of the GNU General Public License as published by the Free Software 10 Foundation; either version 3 of the License, or (at your option) any later 11 version. 12 13 This program is distributed in the hope that it will be useful, but WITHOUT ANY 14 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 PARTICULAR PURPOSE. See the GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License along 18 with this program. If not, see <http://www.gnu.org/licenses/>. 19 """ 20 21 from ula import * 22 import pygame 23 24 WIDTH = 640 25 HEIGHT = 512 26 INTENSITY = 255 27 28 def update_screen(screen, screen_array): 29 30 """ 31 Update the host's 'screen' surface with the contents of the 'screen_array' 32 containing the pixel content of the screen. 33 """ 34 35 surface = pygame.Surface((MAX_WIDTH, MAX_HEIGHT), 0, screen) 36 sa = pygame.surfarray.pixels3d(surface) 37 a = sa.transpose(1, 0, 2) 38 39 # Copy the array to a surface and apply a pixel intensity. 40 41 try: 42 a.flat[:] = screen_array 43 a *= INTENSITY 44 finally: 45 del a, sa 46 47 # Scale the surface to the dimensions of the host's screen and copy the 48 # result to the host's screen. 49 50 screen.blit(pygame.transform.scale(surface, (WIDTH, HEIGHT)), (0, 0)) 51 52 def mainloop(): 53 while 1: 54 pygame.display.flip() 55 event = pygame.event.wait() 56 if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: 57 break 58 59 if __name__ == "__main__": 60 pygame.init() 61 screen = pygame.display.set_mode((WIDTH, HEIGHT), 0) 62 63 ula = get_ula() 64 65 # Test MODE 2. 66 67 ula.set_mode(2); ula.reset() 68 69 ula.ram.fill(0x3000, 0x5800 - 320, encode((1, 6), 4)) 70 ula.ram.fill(0x5800 - 320, 0x8000, encode((2, 7), 4)) 71 ula_screen = update(ula) 72 update_screen(screen, ula_screen) 73 print "Screen updated." 74 mainloop() 75 76 ula.screen_start = 0x3000 + 2 77 ula_screen = update(ula) 78 update_screen(screen, ula_screen) 79 print "Screen updated." 80 mainloop() 81 82 # Test MODE 6. 83 84 ula.set_mode(6); ula.reset() 85 86 ula.ram.fill(0x6000, 0x6f00 + 160, encode((1, 0, 1, 1, 0, 0, 1, 1), 1)) 87 ula.ram.fill(0x6f00 + 160, 0x7f40, encode((1, 0, 1, 0, 1, 0, 1, 0), 1)) 88 ula_screen = update(ula) 89 update_screen(screen, ula_screen) 90 print "Screen updated." 91 mainloop() 92 93 ula.screen_start = 0x6f00 + 160 94 ula_screen = update(ula) 95 update_screen(screen, ula_screen) 96 print "Screen updated." 97 mainloop() 98 99 # vim: tabstop=4 expandtab shiftwidth=4