Working on ppu

This commit is contained in:
Samuel Walker 2025-02-18 22:39:56 -07:00
parent 89a1b4cec6
commit c8ec44fa39
Signed by: piwalker
GPG Key ID: 616B1928705EA4C9
7 changed files with 38 additions and 9 deletions

View File

@ -52,7 +52,7 @@ typedef enum {
SS_LYC = (1 << 6)
} stat_src;
#define LCDS_STAT_INT(src) (lcd_get_context()->lcds & src)
#define LCDS_STAT_INT(src) ((lcd_get_context()->lcds & src) == src)
void lcd_init();

View File

@ -82,6 +82,7 @@ typedef struct {
u32 target_frame_time;
bool paused;
bool frame;
bool debug;
} ppu_context;
void ppu_init();

View File

@ -58,6 +58,14 @@ void lcd_write(u16 address, u8 value) {
u8 *p = (u8 *)&ctx;
p[offset] = value;
if(offset == 2) {
printf("YScroll: %02X\n", value);
}
if(offset == 0xA) {
printf("WinY: %02X\n", value);
}
if(offset == 6) {
//offset FF64
dma_start(value);

View File

@ -35,6 +35,7 @@ void ppu_init() {
LCDS_MODE_SET(MODE_OAM);
memset(ctx.oam_ram, 0, sizeof(ctx.oam_ram));
memset(ctx.vram, 0, sizeof(ctx.vram));
memset(ctx.video_buffer, 0, YRES*XRES*sizeof(u32));
}

View File

@ -42,6 +42,9 @@ u32 fetch_sprite_pixels(int bit, u32 color, u8 bg_color) {
for (int i = 0; i < ppu_get_context()->fetched_entry_count; i++) {
int sp_x = (ppu_get_context()->fetched_entries[i].x - 8) +
((lcd_get_context()->scroll_x % 8));
if(ppu_get_context()->rendering_window) {
sp_x = (ppu_get_context()->fetched_entries[i].x - 8);
}
if (sp_x + 8 < ppu_get_context()->pfc.fifo_x) {
//past this pixel already
@ -71,8 +74,8 @@ u32 fetch_sprite_pixels(int bit, u32 color, u8 bg_color) {
}
if(!bg_priority || bg_color == 0) {
color = (ppu_get_context()->fetched_entries[i].f_pn) ?
lcd_get_context()->sp2_colors[hi|lo] : lcd_get_context()->sp1_colors[hi|lo];
color = ((ppu_get_context()->fetched_entries[i].f_pn) ?
lcd_get_context()->sp2_colors[hi|lo] : lcd_get_context()->sp1_colors[hi|lo]);
if(hi | lo) {
break;
@ -101,7 +104,7 @@ bool pipeline_fifo_add() {
color = lcd_get_context()->bg_colors[0];
}
if(LCDC_OBJ_ENABLE) {
if(LCDC_OBJ_ENABLE && !ppu_get_context()->debug) {
color = fetch_sprite_pixels(bit, color, hi | lo);
}
@ -204,7 +207,7 @@ void pipeline_fetch() {
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);
(ppu_get_context()->window_line % 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) +
@ -220,7 +223,7 @@ void pipeline_fetch() {
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);
(ppu_get_context()->window_line % 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) +
@ -256,12 +259,13 @@ 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()) {
if(ppu_get_context()->pfc.line_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;
ppu_get_context()->pfc.fetch_x = 0;
ppu_get_context()->pfc.fifo_x = 0;
ppu_get_context()->pfc.fetch_x = ppu_get_context()->pfc.line_x;
ppu_get_context()->pfc.fifo_x = ppu_get_context()->pfc.line_x;
ppu_get_context()->pfc.pushed_x = ppu_get_context()->pfc.line_x;
return;
}
if(ppu_get_context()->rendering_window) {

View File

@ -112,6 +112,7 @@ void ppu_mode_xfer() {
if(LCDS_STAT_INT(SS_HBLANK)) {
cpu_request_interrupt(IT_LCD_STAT);
printf("hblank!\n");
}
ppu_get_context()->rendering_window = false;
}
@ -123,6 +124,9 @@ void ppu_mode_vblank() {
if(lcd_get_context()->ly >= LINES_PER_FRAME) {
LCDS_MODE_SET(MODE_OAM);
if(LCDS_STAT_INT(SS_OAM)) {
cpu_request_interrupt(IT_LCD_STAT);
}
lcd_get_context()->ly = 0;
ppu_get_context()->window_line = 0;
}
@ -182,6 +186,9 @@ void ppu_mode_hblank() {
} else {
LCDS_MODE_SET(MODE_OAM);
if(LCDS_STAT_INT(SS_OAM)) {
cpu_request_interrupt(IT_LCD_STAT);
}
}
ppu_get_context()->line_ticks = 0;

View File

@ -305,6 +305,14 @@ void ui_on_key(bool down, u32 key_code) {
printf("Resumed Emulation\n");
}
}
if(key_code == SDLK_d && down == true) {
ppu_get_context()->debug = !ppu_get_context()->debug;
if(ppu_get_context()->debug) {
printf("PPU Debug Enabled\n");
} else {
printf("PPU Debug Disabled\n");
}
}
switch(key_code){
case SDLK_z: gamepad_get_state()->b = down; break;
case SDLK_x: gamepad_get_state()->a = down; break;