This commit is contained in:
2025-02-19 10:20:45 -07:00
parent 2ab09f9b4c
commit 89cfdb4d65
5 changed files with 43 additions and 21 deletions

View File

@ -255,6 +255,23 @@ void pipeline_fifo_reset() {
ppu_get_context()->pfc.pixel_fifo.head = 0;
}
//Rate at wich the screen interpolates between the old and new colors
//Used to simulate the slow response time of the GB's LCD
//A value of zero will always use the exiting screen color, while a 1 will always use the new color
//any value in between will interpolate that percentage between the two
#define INTERPOLATION_RATE 0.5
u32 interpolate(u32 first, u32 second) {
u32 final = 0;
for(int c = 0; c < 4; c++) {
u8 c1 = (first >> (c*8)) & 0xFF;
u8 c2 = (second >> (c*8)) & 0xFF;
u8 cf = (u8)(((((float)c2/(float)0xFF) - ((float)c1/(float)0xFF)) * INTERPOLATION_RATE + ((float)c1/(float)0xFF)) * 0xFF);
final |= cf << (c*8);
}
return final;
}
void pipeline_push_pixel() {
if (ppu_get_context()->pfc.pixel_fifo.size > 8) {
u32 pixel_data = pixel_fifo_pop();
@ -270,13 +287,15 @@ void pipeline_push_pixel() {
}
if(ppu_get_context()->rendering_window) {
ppu_get_context()->video_buffer[ppu_get_context()->pfc.pushed_x +
(lcd_get_context()->ly * XRES)] = pixel_data;
(lcd_get_context()->ly * XRES)] = interpolate(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;
(lcd_get_context()->ly * XRES)] = interpolate(ppu_get_context()->video_buffer[ppu_get_context()->pfc.pushed_x +
(lcd_get_context()->ly * XRES)], pixel_data);
ppu_get_context()->pfc.pushed_x++;
}