1.1 --- a/ula.py Mon Feb 13 22:00:09 2012 +0100
1.2 +++ b/ula.py Sun Feb 26 23:11:44 2012 +0100
1.3 @@ -18,7 +18,7 @@
1.4 MAX_PIXELLINE = MIN_PIXELLINE + MAX_HEIGHT
1.5
1.6 MAX_HSYNC = 75 # the number of cycles in each hsync period
1.7 -MIN_PIXELPOS = 264 # the first cycle involving pixel generation
1.8 +MIN_PIXELPOS = 256 # the first cycle involving pixel generation
1.9 MAX_SCANPOS = 1024 # the number of cycles in each scanline
1.10
1.11 MAX_PIXELPOS = MIN_PIXELPOS + MAX_WIDTH
1.12 @@ -73,7 +73,7 @@
1.13
1.14 def update(self):
1.15 if MIN_PIXELLINE <= self.y < MAX_PIXELLINE:
1.16 - if MIN_PIXELPOS <= self.x < MAX_PIXELPOS:
1.17 + if MIN_PIXELPOS + 8 <= self.x < MAX_PIXELPOS + 8:
1.18 self.screen[self.pos] = self.colour[0]; self.pos += 1
1.19 self.screen[self.pos] = self.colour[1]; self.pos += 1
1.20 self.screen[self.pos] = self.colour[2]; self.pos += 1
1.21 @@ -158,6 +158,8 @@
1.22 self.access = 0 # counter used to determine whether a byte needs reading
1.23 self.ram_address = 0 # address given to the RAM
1.24 self.data = 0 # data read from the RAM
1.25 + self.have_pixels = 0 # whether pixel data has been read
1.26 + self.writing_pixels = 0 # whether pixel data can be written
1.27 self.buffer = [0] * 8 # pixel buffer for decoded RAM data
1.28
1.29 self.reset_vertical()
1.30 @@ -277,8 +279,7 @@
1.31
1.32 def in_frame(self): return MIN_PIXELLINE <= self.y < MAX_PIXELLINE
1.33 def inside_frame(self): return MIN_PIXELLINE < self.y < MAX_PIXELLINE
1.34 - def read_pixels(self): return MIN_PIXELPOS - 8 <= self.x < MAX_PIXELPOS - 8 and self.in_frame()
1.35 - def make_pixels(self): return MIN_PIXELPOS <= self.x < MAX_PIXELPOS and self.in_frame()
1.36 + def read_pixels(self): return MIN_PIXELPOS <= self.x < MAX_PIXELPOS and self.in_frame()
1.37
1.38 def update(self):
1.39
1.40 @@ -312,6 +313,14 @@
1.41 if access_ram:
1.42 self.ram_address = (self.address & 0xff80) >> 7
1.43
1.44 + # Initialise the pixel buffer if appropriate.
1.45 +
1.46 + if not self.writing_pixels and self.have_pixels:
1.47 + self.xcounter = self.xscale
1.48 + self.buffer_index = 0
1.49 + self.fill_pixel_buffer()
1.50 + self.writing_pixels = 1
1.51 +
1.52 # Latch row address, set column address (for ULA access only).
1.53
1.54 elif self.cycle == 1:
1.55 @@ -373,6 +382,7 @@
1.56
1.57 if access_ram:
1.58 self.data = self.data | self.ram.data
1.59 + self.have_pixels = 1
1.60
1.61 # Advance to the next column.
1.62
1.63 @@ -418,34 +428,27 @@
1.64
1.65 # Detect spacing between character rows.
1.66
1.67 - if not self.make_pixels() or self.ssub:
1.68 + if not self.writing_pixels or self.ssub:
1.69 self.video.colour = BLANK
1.70
1.71 # For pixels within the frame, obtain and output the value.
1.72
1.73 else:
1.74 - # Detect the start of the pixel generation.
1.75
1.76 - if self.x == MIN_PIXELPOS:
1.77 - self.xcounter = self.xscale
1.78 - self.buffer_index = 0
1.79 - self.fill_pixel_buffer()
1.80 + self.xcounter -= 1
1.81 + self.video.colour = self.buffer[self.buffer_index]
1.82
1.83 # Scale pixels horizontally, only accessing the next pixel value
1.84 # after the required number of scan positions.
1.85
1.86 - elif self.xcounter == 0:
1.87 + if self.xcounter == 0:
1.88 self.xcounter = self.xscale
1.89 self.buffer_index += 1
1.90
1.91 - # Fill the pixel buffer, assuming that data is available.
1.92 + # Handle the buffer empty condition.
1.93
1.94 if self.buffer_index >= self.buffer_limit:
1.95 - self.buffer_index = 0
1.96 - self.fill_pixel_buffer()
1.97 -
1.98 - self.xcounter -= 1
1.99 - self.video.colour = self.buffer[self.buffer_index]
1.100 + self.writing_pixels = 0
1.101
1.102 self.x += 1
1.103