# HG changeset patch # User Paul Boddie # Date 1466715720 -7200 # Node ID e3c785375378cee8bf135f734d8a26e3c8800593 # Parent 528acbe53d796de8179f98766f6f289b65a79787 Attempted to introduce hardware description language limitations, restructuring to put all state-changing operations in one place, deferring updates of the horizontal position variable. diff -r 528acbe53d79 -r e3c785375378 ula.py --- a/ula.py Wed Jun 22 15:49:54 2016 +0200 +++ b/ula.py Thu Jun 23 23:02:00 2016 +0200 @@ -211,6 +211,7 @@ self.pdata = 0 # decoded RAM data for pixel output self.cycle = 1 # 8-state counter within each 2MHz period self.pcycle = 0 # 8/4/2-state pixel output counter + self.x = 0 self.next_frame() @@ -273,7 +274,7 @@ self.line_start = self.pixel_address = self.screen_start self.line = self.line_start % LINES_PER_ROW self.y = 0 - self.x = 0 + self.x_next = 0 def next_horizontal(self): @@ -281,13 +282,14 @@ self.pixel_address += LINES_PER_ROW self.wrap_address() + self.x_next = self.x + 1 def next_vertical(self): "Reset horizontal state within the active region of the frame." self.y += 1 - self.x = 0 + self.x_next = 0 if self.inside_frame(): self.line += 1 @@ -420,21 +422,12 @@ self.negedge_ram() self.negedge_state() self.negedge_pixel() + self.x = self.x_next def negedge_video(self): "Video signalling." - # Detect the end of the scanline. - - if self.x == MAX_SCANPOS: - self.next_vertical() - - # Detect the end of the frame. - - if self.y == MAX_SCANLINE: - self.next_frame() - # Detect any sync conditions. if self.x == 0: @@ -510,11 +503,6 @@ elif self.cycle == 128: - # Advance to the next column even if an NMI is asserted. - - if self.would_access_ram(): - self.next_horizontal() - # If the ULA accessed RAM, indicate that a read needs completing. if self.access_ram(): @@ -522,10 +510,28 @@ def negedge_state(self): - "Start a new cycle." + "Start a new cycle and update the pixel counters." + + # Detect the end of the scanline. + + if self.x + 1 == MAX_SCANPOS: + + # Detect the end of the frame. + + if self.y + 1 == MAX_SCANLINE: + self.next_frame() + else: + self.next_vertical() + + # Advance to the next column even if an NMI is asserted. + + elif self.cycle == 128 and self.would_access_ram(): + self.next_horizontal() + + else: + self.x_next = self.x + 1 self.cycle = rotate(self.cycle, 1) - self.x += 1 def negedge_pixel(self):