# HG changeset patch # User Paul Boddie # Date 1466189370 -7200 # Node ID b1f2c3de8b1526f4d2ba4a6de88ced78a1091e5f # Parent cc151c813762bccb8d9890cc08e5e602f7b09fe5 Introduced a pixel position counter, eliminating the horizontal position counter and simplifying the logic slightly. diff -r cc151c813762 -r b1f2c3de8b15 ula.py --- a/ula.py Tue Jun 07 14:54:07 2016 +0200 +++ b/ula.py Fri Jun 17 20:49:30 2016 +0200 @@ -37,6 +37,9 @@ MAX_PIXELPOS = MIN_PIXELPOS + MAX_WIDTH +PIXEL_POSITIONS = 8 # the number of pixel positions per byte + # (doubled or quadrupled in lower resolutions) + SCREEN_LIMIT = 0x8000 # the first address after the screen memory MAX_MEMORY = 0x10000 # the number of addressable memory locations MAX_RAM = 0x10000 # the number of addressable RAM locations (64Kb in each IC) @@ -268,10 +271,6 @@ self.footer = rows * LINES_PER_ROW self.margin = MAX_SCANLINE - rows * (LINES_PER_ROW + self.spacing) + self.spacing - # Internal pixel buffer size. - - self.buffer_limit = 8 / self.depth - def vsync(self, value=0): "Signal the start of a frame." @@ -380,7 +379,7 @@ # Initialise the pixel buffer if appropriate. if not self.writing_pixels and self.have_pixels: - self.xcounter = self.xscale + self.pixelpos = 0 self.buffer_index = 0 self.fill_pixel_buffer() self.writing_pixels = 1 @@ -509,21 +508,19 @@ # For pixels within the frame, obtain and output the value. else: - - self.xcounter -= 1 + self.pixelpos += 1 self.video.colour = self.buffer[self.buffer_index] # Scale pixels horizontally, only accessing the next pixel value # after the required number of scan positions. - if self.xcounter == 0: - self.xcounter = self.xscale + if self.pixelpos % self.xscale == 0: self.buffer_index += 1 - # Handle the buffer empty condition. + # Finish writing pixels. - if self.buffer_index >= self.buffer_limit: - self.writing_pixels = 0 + if self.pixelpos == PIXEL_POSITIONS: + self.writing_pixels = 0 self.x += 1