fixed scroll?

This commit is contained in:
Samuel Walker 2025-02-01 20:53:13 -07:00
parent 89a99b160d
commit 36a428bcea
Signed by: piwalker
GPG Key ID: 616B1928705EA4C9
5 changed files with 59 additions and 28 deletions

View File

@ -77,6 +77,8 @@ typedef struct {
u32 current_frame;
u32 line_ticks;
u32 *video_buffer;
bool rendering_window;
} ppu_context;
void ppu_init();

View File

@ -318,7 +318,8 @@ bool cart_battery_load(){
FILE *fp = fopen(fn, "rb");
if(!fp) {
fprintf(stderr, "unable to open: %s\n", fn);
printf("No battery save found.");
return true;
}
fread(ctx.ram_bank, 0x2000, 1, fp);

View File

@ -28,6 +28,8 @@ void ppu_init() {
ctx.fetched_entry_count = 0;
ctx.window_line = 0;
ctx.rendering_window = false;
lcd_init();
LCDS_MODE_SET(MODE_OAM);

View File

@ -162,9 +162,7 @@ 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) {
if (ppu_get_context()->rendering_window) {
u8 w_tile_y = ppu_get_context()->window_line / 8;
@ -177,7 +175,6 @@ void pipeline_load_window_tile() {
}
}
}
}
void pipeline_fetch() {
switch(ppu_get_context()->pfc.cur_fetch_state) {
@ -204,9 +201,15 @@ void pipeline_fetch() {
} break;
case FS_DATA0: {
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: {
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,16 +244,40 @@ 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.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++;
}
@ -261,11 +294,3 @@ 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;
}

View File

@ -113,6 +113,7 @@ void ppu_mode_xfer() {
if(LCDS_STAT_INT(SS_HBLANK)) {
cpu_request_interrupt(IT_LCD_STAT);
}
ppu_get_context()->rendering_window = false;
}
}