ppu work
This commit is contained in:
parent
2ab09f9b4c
commit
89cfdb4d65
@ -93,10 +93,10 @@ int emu_run(int argc, char **argv) {
|
|||||||
while(!ctx.die) {
|
while(!ctx.die) {
|
||||||
sleep_ms(1);
|
sleep_ms(1);
|
||||||
ui_handle_events();
|
ui_handle_events();
|
||||||
if (prev_frame != ppu_get_context()->current_frame) {
|
//if (prev_frame != ppu_get_context()->current_frame) {
|
||||||
ui_update();
|
ui_update();
|
||||||
}
|
//}
|
||||||
prev_frame = ppu_get_context()->current_frame;
|
//prev_frame = ppu_get_context()->current_frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
static lcd_context ctx;
|
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() {
|
lcd_context *lcd_get_context() {
|
||||||
return &ctx;
|
return &ctx;
|
||||||
|
30
lib/ppu.c
30
lib/ppu.c
@ -40,21 +40,23 @@ void ppu_init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ppu_tick() {
|
void ppu_tick() {
|
||||||
ctx.line_ticks++;
|
if(LCDC_LCD_ENABLE){
|
||||||
|
ctx.line_ticks++;
|
||||||
|
|
||||||
switch(LCDS_MODE) {
|
switch(LCDS_MODE) {
|
||||||
case MODE_OAM:
|
case MODE_OAM:
|
||||||
ppu_mode_oam();
|
ppu_mode_oam();
|
||||||
break;
|
break;
|
||||||
case MODE_XFER:
|
case MODE_XFER:
|
||||||
ppu_mode_xfer();
|
ppu_mode_xfer();
|
||||||
break;
|
break;
|
||||||
case MODE_VBLANK:
|
case MODE_VBLANK:
|
||||||
ppu_mode_vblank();
|
ppu_mode_vblank();
|
||||||
break;
|
break;
|
||||||
case MODE_HBLANK:
|
case MODE_HBLANK:
|
||||||
ppu_mode_hblank();
|
ppu_mode_hblank();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,6 +255,23 @@ void pipeline_fifo_reset() {
|
|||||||
ppu_get_context()->pfc.pixel_fifo.head = 0;
|
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() {
|
void pipeline_push_pixel() {
|
||||||
if (ppu_get_context()->pfc.pixel_fifo.size > 8) {
|
if (ppu_get_context()->pfc.pixel_fifo.size > 8) {
|
||||||
u32 pixel_data = pixel_fifo_pop();
|
u32 pixel_data = pixel_fifo_pop();
|
||||||
@ -270,13 +287,15 @@ void pipeline_push_pixel() {
|
|||||||
}
|
}
|
||||||
if(ppu_get_context()->rendering_window) {
|
if(ppu_get_context()->rendering_window) {
|
||||||
ppu_get_context()->video_buffer[ppu_get_context()->pfc.pushed_x +
|
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++;
|
ppu_get_context()->pfc.pushed_x++;
|
||||||
}else {
|
}else {
|
||||||
if(ppu_get_context()->pfc.line_x >= (lcd_get_context()->scroll_x % 8)) {
|
if(ppu_get_context()->pfc.line_x >= (lcd_get_context()->scroll_x % 8)) {
|
||||||
ppu_get_context()->video_buffer[ppu_get_context()->pfc.pushed_x +
|
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++;
|
ppu_get_context()->pfc.pushed_x++;
|
||||||
}
|
}
|
||||||
|
3
lib/ui.c
3
lib/ui.c
@ -5,6 +5,7 @@
|
|||||||
#include <bus.h>
|
#include <bus.h>
|
||||||
#include <audio.h>
|
#include <audio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <lcd.h>
|
||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <SDL_ttf.h>
|
#include <SDL_ttf.h>
|
||||||
@ -58,7 +59,7 @@ void ui_init(){
|
|||||||
SDL_SetWindowPosition(sdlDebugWindow, x+SCREEN_WIDTH, y);
|
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) {
|
void display_tile(SDL_Surface *surface, u16 startLocation, u16 tileNum, int x, int y) {
|
||||||
SDL_Rect rc;
|
SDL_Rect rc;
|
||||||
|
Loading…
Reference in New Issue
Block a user