# HG changeset patch # User Paul Boddie # Date 1330294304 -3600 # Node ID 726152e626d558fd3336c7ecdc2f0a46018cc8d6 # Parent 99b0ecdba781b21bdf32c25df7f1a77c33b26b96 Simplified the logic slightly around reading and displaying pixels. diff -r 99b0ecdba781 -r 726152e626d5 ula.py --- a/ula.py Mon Feb 13 22:00:09 2012 +0100 +++ b/ula.py Sun Feb 26 23:11:44 2012 +0100 @@ -18,7 +18,7 @@ MAX_PIXELLINE = MIN_PIXELLINE + MAX_HEIGHT MAX_HSYNC = 75 # the number of cycles in each hsync period -MIN_PIXELPOS = 264 # the first cycle involving pixel generation +MIN_PIXELPOS = 256 # the first cycle involving pixel generation MAX_SCANPOS = 1024 # the number of cycles in each scanline MAX_PIXELPOS = MIN_PIXELPOS + MAX_WIDTH @@ -73,7 +73,7 @@ def update(self): if MIN_PIXELLINE <= self.y < MAX_PIXELLINE: - if MIN_PIXELPOS <= self.x < MAX_PIXELPOS: + if MIN_PIXELPOS + 8 <= self.x < MAX_PIXELPOS + 8: self.screen[self.pos] = self.colour[0]; self.pos += 1 self.screen[self.pos] = self.colour[1]; self.pos += 1 self.screen[self.pos] = self.colour[2]; self.pos += 1 @@ -158,6 +158,8 @@ self.access = 0 # counter used to determine whether a byte needs reading self.ram_address = 0 # address given to the RAM self.data = 0 # data read from the RAM + self.have_pixels = 0 # whether pixel data has been read + self.writing_pixels = 0 # whether pixel data can be written self.buffer = [0] * 8 # pixel buffer for decoded RAM data self.reset_vertical() @@ -277,8 +279,7 @@ def in_frame(self): return MIN_PIXELLINE <= self.y < MAX_PIXELLINE def inside_frame(self): return MIN_PIXELLINE < self.y < MAX_PIXELLINE - def read_pixels(self): return MIN_PIXELPOS - 8 <= self.x < MAX_PIXELPOS - 8 and self.in_frame() - def make_pixels(self): return MIN_PIXELPOS <= self.x < MAX_PIXELPOS and self.in_frame() + def read_pixels(self): return MIN_PIXELPOS <= self.x < MAX_PIXELPOS and self.in_frame() def update(self): @@ -312,6 +313,14 @@ if access_ram: self.ram_address = (self.address & 0xff80) >> 7 + # Initialise the pixel buffer if appropriate. + + if not self.writing_pixels and self.have_pixels: + self.xcounter = self.xscale + self.buffer_index = 0 + self.fill_pixel_buffer() + self.writing_pixels = 1 + # Latch row address, set column address (for ULA access only). elif self.cycle == 1: @@ -373,6 +382,7 @@ if access_ram: self.data = self.data | self.ram.data + self.have_pixels = 1 # Advance to the next column. @@ -418,34 +428,27 @@ # Detect spacing between character rows. - if not self.make_pixels() or self.ssub: + if not self.writing_pixels or self.ssub: self.video.colour = BLANK # For pixels within the frame, obtain and output the value. else: - # Detect the start of the pixel generation. - if self.x == MIN_PIXELPOS: - self.xcounter = self.xscale - self.buffer_index = 0 - self.fill_pixel_buffer() + self.xcounter -= 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. - elif self.xcounter == 0: + if self.xcounter == 0: self.xcounter = self.xscale self.buffer_index += 1 - # Fill the pixel buffer, assuming that data is available. + # Handle the buffer empty condition. if self.buffer_index >= self.buffer_limit: - self.buffer_index = 0 - self.fill_pixel_buffer() - - self.xcounter -= 1 - self.video.colour = self.buffer[self.buffer_index] + self.writing_pixels = 0 self.x += 1