1.1 --- a/ula.py Sun Dec 04 21:43:45 2011 +0100
1.2 +++ b/ula.py Mon Dec 05 01:20:39 2011 +0100
1.3 @@ -10,12 +10,13 @@
1.4
1.5 WIDTH = 640
1.6 HEIGHT = 512
1.7 +INTENSITY = 255
1.8
1.9 LINES_PER_ROW = 8
1.10 MAX_HEIGHT = 256
1.11 SCREEN_LIMIT = 0x8000
1.12 MAX_MEMORY = 0x10000
1.13 -INTENSITY = 255
1.14 +BLANK = (0, 0, 0)
1.15
1.16 def update(screen, ula):
1.17
1.18 @@ -41,8 +42,8 @@
1.19
1.20 modes = [
1.21 (640, 1, 32), (320, 2, 32), (160, 4, 32), # (width, depth, rows)
1.22 - (640, 1, 24), (320, 1, 32), (160, 2, 32),
1.23 - (320, 1, 24)
1.24 + (640, 1, 25), (320, 1, 32), (160, 2, 32),
1.25 + (320, 1, 25)
1.26 ]
1.27
1.28 palette = range(0, 8) * 2
1.29 @@ -75,15 +76,29 @@
1.30 * number of entries in the pixel buffer
1.31 """
1.32
1.33 - self.width, self.depth, self.rows = self.modes[mode]
1.34 + self.width, self.depth, rows = self.modes[mode]
1.35 +
1.36 + row_size = (self.width * self.depth * LINES_PER_ROW) / 8 # bits per row -> bytes per row
1.37
1.38 - row_size = (self.width * self.depth * LINES_PER_ROW) / 8 # bits per row -> bytes per row
1.39 + # Memory access configuration.
1.40 +
1.41 + self.screen_size = row_size * rows
1.42 + self.screen_start = (SCREEN_LIMIT - self.screen_size) & 0xff00 # limitation on positioning
1.43 +
1.44 + # Scanline configuration.
1.45
1.46 - self.screen_size = row_size * self.rows
1.47 - self.screen_start = SCREEN_LIMIT - self.screen_size
1.48 - self.xscale = WIDTH / self.width # pixel width in display pixels
1.49 - self.yscale = HEIGHT / (self.rows * LINES_PER_ROW) # pixel height in display pixels
1.50 - self.spacing = MAX_HEIGHT / self.rows - LINES_PER_ROW # pixels between rows
1.51 + self.xscale = WIDTH / self.width # pixel width in display pixels
1.52 + self.yscale = HEIGHT / (rows * LINES_PER_ROW) # pixel height in display pixels
1.53 +
1.54 + self.spacing = MAX_HEIGHT / rows - LINES_PER_ROW # pixels between rows
1.55 +
1.56 + # Start of unused region.
1.57 +
1.58 + self.footer = rows * LINES_PER_ROW
1.59 + self.margin = MAX_HEIGHT - rows * (LINES_PER_ROW + self.spacing) + self.spacing
1.60 +
1.61 + # Internal pixel buffer size.
1.62 +
1.63 self.buffer_limit = 8 / self.depth
1.64
1.65 def vsync(self):
1.66 @@ -93,6 +108,7 @@
1.67 self.line_start = self.address = self.screen_start
1.68 self.line = 0
1.69 self.ysub = 0
1.70 + self.ssub = 0
1.71 self.reset_horizontal()
1.72
1.73 def reset_horizontal(self):
1.74 @@ -106,6 +122,12 @@
1.75
1.76 "Signal the end of a line."
1.77
1.78 + # Support spacing between character rows.
1.79 +
1.80 + if self.ssub:
1.81 + self.ssub -= 1
1.82 + return
1.83 +
1.84 self.reset_horizontal()
1.85
1.86 # Scale pixels vertically.
1.87 @@ -123,7 +145,9 @@
1.88 self.ysub = 0
1.89 self.line += 1
1.90
1.91 - if self.line < LINES_PER_ROW:
1.92 + # If not on a row boundary, move to the next line.
1.93 +
1.94 + if self.line % LINES_PER_ROW:
1.95 self.address = self.line_start + 1
1.96 self.wrap_address()
1.97
1.98 @@ -134,12 +158,17 @@
1.99 self.address -= LINES_PER_ROW - 1
1.100 self.wrap_address()
1.101
1.102 - self.line_start = self.address
1.103 + # Test for the footer region.
1.104 +
1.105 + if self.spacing and self.line == self.footer:
1.106 + self.ssub = self.margin * self.yscale
1.107 + return
1.108
1.109 - # Move on to the next row if appropriate.
1.110 + # Support spacing between character rows.
1.111
1.112 - if self.line == LINES_PER_ROW:
1.113 - self.line = 0
1.114 + self.ssub = self.spacing * self.yscale
1.115 +
1.116 + self.line_start = self.address
1.117
1.118 def get_pixel_colour(self):
1.119
1.120 @@ -147,6 +176,11 @@
1.121 Return a pixel colour by reading from the pixel buffer.
1.122 """
1.123
1.124 + # Detect spacing between character rows.
1.125 +
1.126 + if self.ssub:
1.127 + return BLANK
1.128 +
1.129 # Scale pixels horizontally.
1.130
1.131 if self.xsub == self.xscale:
1.132 @@ -268,4 +302,17 @@
1.133 update(a, ula)
1.134 mainloop()
1.135
1.136 + # Test MODE 6.
1.137 +
1.138 + ula.set_mode(6)
1.139 +
1.140 + fill(memory, 0x6000, 0x6f00 + 160, encode((1, 0, 1, 1, 0, 0, 1, 1), 1))
1.141 + fill(memory, 0x6f00 + 160, 0x7f40, encode((1, 0, 1, 0, 1, 0, 1, 0), 1))
1.142 + update(a, ula)
1.143 + mainloop()
1.144 +
1.145 + ula.screen_start = 0x6f00 + 160
1.146 + update(a, ula)
1.147 + mainloop()
1.148 +
1.149 # vim: tabstop=4 expandtab shiftwidth=4