@@ -182,7 +182,60 @@ impl Ppu {
182
182
let tile_n = self . vram [ self . mirror_vram_addr ( ( nt_start + offset) as u16 ) as usize ] ;
183
183
let bgp_idx = self . palette_for_bg_tile ( ( x, y) , nt_start) ;
184
184
let palette = self . lookup_palette ( bgp_idx) ;
185
- frame. draw_bg_tile ( pattern_table, tile_n as usize , ( x, y) , palette) ;
185
+ frame. draw_bg_tile ( pattern_table, tile_n as usize , ( x, y) , 0 , palette) ;
186
+ }
187
+ }
188
+ }
189
+
190
+ /// Draws the entire possible background of 2 frames, but it gets filtered within, which you can then filter by applying a windowed viewport
191
+ pub fn draw_scrollable_background ( & self , frame : & mut Frame ) {
192
+ let bank = self . get_background_pattern_bank ( ) ;
193
+ let pattern_table =
194
+ & self . chr_rom [ bank * PATTERN_TABLE_SIZE ..( bank + 1 ) * PATTERN_TABLE_SIZE ] ;
195
+
196
+ // In horizontal scrolling, this is the nametable at the LEFT of the screen
197
+ let which_nametable = self
198
+ . registers
199
+ . control
200
+ . intersection ( ControlRegister :: NAMETABLE )
201
+ . bits ( ) as usize ;
202
+ assert ! ( which_nametable <= 3 ) ;
203
+ let nt_start = which_nametable * 0x400 ;
204
+
205
+ // self.registers.control.
206
+
207
+ // Determine which nametable is on the left
208
+ let nts = if nt_start == 0 {
209
+ [ 0 , 0x400 ]
210
+ } else {
211
+ [ 0x400 , 0x800 ]
212
+ } ;
213
+
214
+ let x_scroll: usize = self . registers . scroll . x_scroll as usize ;
215
+ let y_scroll: usize = self . registers . scroll . y_scroll as usize ;
216
+ // TODO
217
+ // if self.registers.control.contains(ControlRegister::X_SCROLL) {
218
+ // x_scroll += 256;
219
+ // }
220
+
221
+ let rows = 30 ;
222
+ let cols = 32 ;
223
+ for tile_y in 0 ..rows {
224
+ for ( nt_idx, & nt_start) in nts. iter ( ) . enumerate ( ) {
225
+ for tile_x in 0 ..cols {
226
+ let offset = tile_y * cols + tile_x;
227
+ let tile_n =
228
+ self . vram [ self . mirror_vram_addr ( ( nt_start + offset) as u16 ) as usize ] ;
229
+ let bgp_idx = self . palette_for_bg_tile ( ( tile_x, tile_y) , nt_start) ;
230
+ let palette = self . lookup_palette ( bgp_idx) ;
231
+ frame. draw_bg_tile (
232
+ pattern_table,
233
+ tile_n as usize ,
234
+ ( tile_x + cols * ( nt_idx) , tile_y) ,
235
+ x_scroll,
236
+ palette,
237
+ ) ;
238
+ }
186
239
}
187
240
}
188
241
}
@@ -477,8 +530,7 @@ impl Ppu {
477
530
let sprite0 = self . parse_sprite_from_oam_data ( & self . oam_data [ 0 ..4 ] ) ;
478
531
let ( scanline_y, scanline_x) = self . get_tick_status ( ) ;
479
532
480
- scanline_y >= sprite0. y as usize
481
- && ( scanline_x % CYCLES_PER_SCANLINE ) >= sprite0. x as usize
533
+ scanline_y >= sprite0. y as usize && ( scanline_x % CYCLES_PER_SCANLINE ) >= sprite0. x as usize
482
534
}
483
535
}
484
536
0 commit comments