@@ -105,22 +105,19 @@ def xor_pixel(self, x, y, plane):
105105 collision = (pixel != 0 )
106106 new_pixel = pixel ^ 0xFF
107107 plane .write (vram_loc , new_pixel )
108- self ._render_pixel (x , y )
109-
108+ self ._render_pixel (vram_loc )
110109 return collision
111110
112- def _render_pixel (self , x , y ):
111+ def _render_pixel (self , vram_loc ):
113112 # Render the pixel to the display
114- vram_loc = x + y * self .vid_width
113+ ram_banks = self .ram_banks
115114 colour = 0
116115
117116 for plane_num in range (self .num_planes ):
118- if self . ram_banks [plane_num ].read (vram_loc ):
117+ if ram_banks [plane_num ].read (vram_loc ):
119118 colour += 2 ** plane_num
120119
121- if self .vid_cache .read (vram_loc ) != colour :
122- self .frame_delta [(x , y )] = colour
123- self .vid_cache .write (vram_loc , colour )
120+ self .frame_delta [vram_loc ] = colour
124121
125122 # Half-pixel vertical scrolling is unsupported in 64x32 pixel mode
126123
@@ -184,17 +181,26 @@ def scroll_down(self, rows):
184181
185182 def _redraw_all (self ):
186183 # Redraw whole screen after a scroll. The video cache should take the load off the renderer a bit
187- for y in range (self .vid_height ):
188- for x in range (self .vid_width ):
189- self ._render_pixel (x , y )
184+ render_pixel = self ._render_pixel
185+
186+ for vram_loc in range (self .vid_size ):
187+ render_pixel (vram_loc )
190188
191189 def refresh_display (self ):
192190 # Request the renderer updates altered pixels and then refreshes the display. This method results in a huge
193191 # (around 5x) speed up when using PyPy with graphically-intensive games, and a tiny improvement with CPython.
194- for xy , colour in self .frame_delta .items ():
195- self .renderer .set_pixel (* xy , colour )
192+ vid_width = self .vid_width
193+ vid_cache_read = self .vid_cache .read
194+ vid_cache_write = self .vid_cache .write
195+ renderer_set_pixel = self .renderer .set_pixel
196+ content_changed = False
197+
198+ for vram_loc , colour in self .frame_delta .items ():
199+ if vid_cache_read (vram_loc ) != colour :
200+ renderer_set_pixel (vram_loc % vid_width , vram_loc // vid_width , colour )
201+ vid_cache_write (vram_loc , colour )
202+ content_changed = True
196203
197- content_changed = bool (self .frame_delta )
198204 self .frame_delta .clear ()
199205 self .renderer .refresh_display (content_changed )
200206
0 commit comments