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

View File

@ -93,10 +93,10 @@ int emu_run(int argc, char **argv) {
while(!ctx.die) {
sleep_ms(1);
ui_handle_events();
if (prev_frame != ppu_get_context()->current_frame) {
//if (prev_frame != ppu_get_context()->current_frame) {
ui_update();
}
prev_frame = ppu_get_context()->current_frame;
//}
//prev_frame = ppu_get_context()->current_frame;
}

View File

@ -4,7 +4,7 @@
static lcd_context ctx;
static unsigned long colors_default[4] = {0xFFFFFFFF, 0xFFAAAAAA, 0xFF555555, 0xFF000000};
static unsigned long colors_default[4] = {0xFF759833, 0xFF588F51, 0xFF3B7560, 0xFF2E615A};
lcd_context *lcd_get_context() {
return &ctx;

View File

@ -40,6 +40,7 @@ void ppu_init() {
}
void ppu_tick() {
if(LCDC_LCD_ENABLE){
ctx.line_ticks++;
switch(LCDS_MODE) {
@ -56,6 +57,7 @@ void ppu_tick() {
ppu_mode_hblank();
break;
}
}
}
void ppu_oam_write(u16 address, u8 value) {

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++;
}

View File

@ -5,6 +5,7 @@
#include <bus.h>
#include <audio.h>
#include <string.h>
#include <lcd.h>
#include <SDL.h>
#include <SDL_ttf.h>
@ -58,7 +59,7 @@ void ui_init(){
SDL_SetWindowPosition(sdlDebugWindow, x+SCREEN_WIDTH, y);
}
static unsigned long tile_colors[4] = {0xFFFFFFFF, 0xFFAAAAAA, 0xFF555555, 0xFF000000};
static unsigned long tile_colors[4] = {0xFF759833, 0xFF588F51, 0xFF3B7560, 0xFF2E615A};
void display_tile(SDL_Surface *surface, u16 startLocation, u16 tileNum, int x, int y) {
SDL_Rect rc;