fixed scroll?

This commit is contained in:
2025-02-01 20:53:13 -07:00
parent 89a99b160d
commit 36a428bcea
5 changed files with 59 additions and 28 deletions

View File

@ -162,19 +162,16 @@ void pipeline_load_window_tile() {
u8 window_y = lcd_get_context()->win_y;
if (ppu_get_context()->pfc.fetch_x + 7 >= lcd_get_context()->win_x &&
ppu_get_context()->pfc.fetch_x + 7 < lcd_get_context()->win_x + YRES + 14) {
if(lcd_get_context()->ly >= window_y && lcd_get_context()->ly < window_y + XRES) {
u8 w_tile_y = ppu_get_context()->window_line / 8;
if (ppu_get_context()->rendering_window) {
u8 w_tile_y = ppu_get_context()->window_line / 8;
ppu_get_context()->pfc.bgw_fetch_data[0] = bus_read(LCDC_WIN_MAP_AREA +
((ppu_get_context()->pfc.fetch_x + 7 - lcd_get_context()->win_x) / 8) +
(w_tile_y * 32));
ppu_get_context()->pfc.bgw_fetch_data[0] = bus_read(LCDC_WIN_MAP_AREA +
((ppu_get_context()->pfc.fetch_x + 7 - lcd_get_context()->win_x) / 8) +
(w_tile_y * 32));
if(LCDC_BGW_DATA_AREA == 0x8800){
ppu_get_context()->pfc.bgw_fetch_data[0] += 128;
}
if(LCDC_BGW_DATA_AREA == 0x8800){
ppu_get_context()->pfc.bgw_fetch_data[0] += 128;
}
}
}
@ -204,9 +201,15 @@ void pipeline_fetch() {
} break;
case FS_DATA0: {
ppu_get_context()->pfc.bgw_fetch_data[1] = bus_read(LCDC_BGW_DATA_AREA +
(ppu_get_context()->pfc.bgw_fetch_data[0] * 16) +
ppu_get_context()->pfc.tile_y);
if(ppu_get_context()->rendering_window){
ppu_get_context()->pfc.bgw_fetch_data[1] = bus_read(LCDC_BGW_DATA_AREA +
(ppu_get_context()->pfc.bgw_fetch_data[0] * 16) +
(lcd_get_context()->ly % 8) * 2);
} else {
ppu_get_context()->pfc.bgw_fetch_data[1] = bus_read(LCDC_BGW_DATA_AREA +
(ppu_get_context()->pfc.bgw_fetch_data[0] * 16) +
ppu_get_context()->pfc.tile_y);
}
pipeline_load_sprite_data(0);
@ -214,9 +217,15 @@ void pipeline_fetch() {
} break;
case FS_DATA1: {
ppu_get_context()->pfc.bgw_fetch_data[2] = bus_read(LCDC_BGW_DATA_AREA +
(ppu_get_context()->pfc.bgw_fetch_data[0] * 16) +
ppu_get_context()->pfc.tile_y + 1);
if(ppu_get_context()->rendering_window){
ppu_get_context()->pfc.bgw_fetch_data[2] = bus_read(LCDC_BGW_DATA_AREA +
(ppu_get_context()->pfc.bgw_fetch_data[0] * 16) + 1 +
(lcd_get_context()->ly % 8) * 2);
} else {
ppu_get_context()->pfc.bgw_fetch_data[2] = bus_read(LCDC_BGW_DATA_AREA +
(ppu_get_context()->pfc.bgw_fetch_data[0] * 16) +
ppu_get_context()->pfc.tile_y + 1);
}
pipeline_load_sprite_data(1);
@ -235,15 +244,39 @@ void pipeline_fetch() {
}
}
void pipeline_fifo_reset() {
while(ppu_get_context()->pfc.pixel_fifo.size) {
pixel_fifo_pop();
}
ppu_get_context()->pfc.pixel_fifo.head = 0;
}
void pipeline_push_pixel() {
if (ppu_get_context()->pfc.pixel_fifo.size > 8) {
u32 pixel_data = pixel_fifo_pop();
if(ppu_get_context()->pfc.line_x >= (lcd_get_context()->scroll_x % 8)) {
ppu_get_context()->video_buffer[ppu_get_context()->pfc.pushed_x +
(lcd_get_context()->ly * XRES)] = pixel_data;
if(ppu_get_context()->pfc.pushed_x+7 >= lcd_get_context()->win_x && lcd_get_context()->ly >= lcd_get_context()->win_y && !ppu_get_context()->rendering_window && window_visible()) {
ppu_get_context()->rendering_window = true;
pipeline_fifo_reset();
ppu_get_context()->pfc.cur_fetch_state = FS_TILE;
printf("Window X: %d\n", lcd_get_context()->win_x);
ppu_get_context()->pfc.fetch_x = 0;
ppu_get_context()->pfc.fifo_x = 0;
return;
}
if(ppu_get_context()->rendering_window) {
ppu_get_context()->video_buffer[ppu_get_context()->pfc.pushed_x +
(lcd_get_context()->ly * XRES)] = pixel_data;
ppu_get_context()->pfc.pushed_x++;
}else {
if(ppu_get_context()->pfc.line_x >= (lcd_get_context()->scroll_x % 8)) {
ppu_get_context()->video_buffer[ppu_get_context()->pfc.pushed_x +
(lcd_get_context()->ly * XRES)] = pixel_data;
ppu_get_context()->pfc.pushed_x++;
}
}
ppu_get_context()->pfc.line_x++;
@ -260,12 +293,4 @@ void pipeline_process() {
}
pipeline_push_pixel();
}
void pipeline_fifo_reset() {
while(ppu_get_context()->pfc.pixel_fifo.size) {
pixel_fifo_pop();
}
ppu_get_context()->pfc.pixel_fifo.head = 0;
}