1.1 --- a/ula.py Wed Jun 22 15:49:54 2016 +0200
1.2 +++ b/ula.py Thu Jun 23 23:02:00 2016 +0200
1.3 @@ -211,6 +211,7 @@
1.4 self.pdata = 0 # decoded RAM data for pixel output
1.5 self.cycle = 1 # 8-state counter within each 2MHz period
1.6 self.pcycle = 0 # 8/4/2-state pixel output counter
1.7 + self.x = 0
1.8
1.9 self.next_frame()
1.10
1.11 @@ -273,7 +274,7 @@
1.12 self.line_start = self.pixel_address = self.screen_start
1.13 self.line = self.line_start % LINES_PER_ROW
1.14 self.y = 0
1.15 - self.x = 0
1.16 + self.x_next = 0
1.17
1.18 def next_horizontal(self):
1.19
1.20 @@ -281,13 +282,14 @@
1.21
1.22 self.pixel_address += LINES_PER_ROW
1.23 self.wrap_address()
1.24 + self.x_next = self.x + 1
1.25
1.26 def next_vertical(self):
1.27
1.28 "Reset horizontal state within the active region of the frame."
1.29
1.30 self.y += 1
1.31 - self.x = 0
1.32 + self.x_next = 0
1.33
1.34 if self.inside_frame():
1.35 self.line += 1
1.36 @@ -420,21 +422,12 @@
1.37 self.negedge_ram()
1.38 self.negedge_state()
1.39 self.negedge_pixel()
1.40 + self.x = self.x_next
1.41
1.42 def negedge_video(self):
1.43
1.44 "Video signalling."
1.45
1.46 - # Detect the end of the scanline.
1.47 -
1.48 - if self.x == MAX_SCANPOS:
1.49 - self.next_vertical()
1.50 -
1.51 - # Detect the end of the frame.
1.52 -
1.53 - if self.y == MAX_SCANLINE:
1.54 - self.next_frame()
1.55 -
1.56 # Detect any sync conditions.
1.57
1.58 if self.x == 0:
1.59 @@ -510,11 +503,6 @@
1.60
1.61 elif self.cycle == 128:
1.62
1.63 - # Advance to the next column even if an NMI is asserted.
1.64 -
1.65 - if self.would_access_ram():
1.66 - self.next_horizontal()
1.67 -
1.68 # If the ULA accessed RAM, indicate that a read needs completing.
1.69
1.70 if self.access_ram():
1.71 @@ -522,10 +510,28 @@
1.72
1.73 def negedge_state(self):
1.74
1.75 - "Start a new cycle."
1.76 + "Start a new cycle and update the pixel counters."
1.77 +
1.78 + # Detect the end of the scanline.
1.79 +
1.80 + if self.x + 1 == MAX_SCANPOS:
1.81 +
1.82 + # Detect the end of the frame.
1.83 +
1.84 + if self.y + 1 == MAX_SCANLINE:
1.85 + self.next_frame()
1.86 + else:
1.87 + self.next_vertical()
1.88 +
1.89 + # Advance to the next column even if an NMI is asserted.
1.90 +
1.91 + elif self.cycle == 128 and self.would_access_ram():
1.92 + self.next_horizontal()
1.93 +
1.94 + else:
1.95 + self.x_next = self.x + 1
1.96
1.97 self.cycle = rotate(self.cycle, 1)
1.98 - self.x += 1
1.99
1.100 def negedge_pixel(self):
1.101