Finish ppu, and mbc1 mapping

This commit is contained in:
2025-02-01 19:05:25 -07:00
parent 2603916972
commit 89a99b160d
17 changed files with 779 additions and 18 deletions

View File

@ -24,4 +24,8 @@ bool cart_load(char *cart);
rom_header *get_rom_header();
u8 cart_read(u16 address);
void cart_write(u16 address, u8 value);
void cart_write(u16 address, u8 value);
bool cart_need_save();
bool cart_battery_load();
bool cart_battery_save();

22
include/gamepad.h Normal file
View File

@ -0,0 +1,22 @@
#pragma once
#include <common.h>
typedef struct {
bool start;
bool select;
bool a;
bool b;
bool up;
bool down;
bool left;
bool right;
} gamepad_state;
void gamepad_init();
bool gamepad_button_sel();
bool gamepad_dir_sel();
void gamepad_set_sel(u8 value);
gamepad_state *gamepad_get_state();
u8 gamepad_get_output();

View File

@ -41,7 +41,7 @@ lcd_context *lcd_get_context();
#define LCDC_LCD_ENABLE (BIT(lcd_get_context()->lcdc, 7))
#define LCDS_MODE ((lcd_mode)(lcd_get_context()->lcds & 0b11))
#define LCDS_MODE_SET(mode) { lcd_get_context()->lcds &= ~0b11; lcd_get_context()->lcdc |= mode; }
#define LCDS_MODE_SET(mode) { lcd_get_context()->lcds &= ~0b11; lcd_get_context()->lcds |= mode; }
#define LCDS_LYC (BIT(lcd_get_context()->lcds, 2))
#define LCDS_LYC_SET(b) BIT_SET(lcd_get_context()->lcds, 2, b)

View File

@ -7,23 +7,73 @@ static const int TICKS_PER_LINE = 456;
static const int YRES = 144;
static const int XRES = 160;
u32 target_frame_time;
typedef enum {
FS_TILE,
FS_DATA0,
FS_DATA1,
FS_IDLE,
FS_PUSH
} fetch_state;
typedef struct _fifo_entry {
struct _fifo_entry *next;
u32 value;
} fifo_entry;
typedef struct {
fifo_entry *head;
fifo_entry *tail;
u32 size; //32 bit color
} fifo;
typedef struct {
fetch_state cur_fetch_state;
fifo pixel_fifo;
u8 line_x;
u8 pushed_x;
u8 fetch_x;
u8 bgw_fetch_data[3];
u8 fetch_entry_data[6]; //oam data
u8 map_y;
u8 map_x;
u8 tile_y;
u8 fifo_x;
} pixel_fifo_context;
typedef struct {
u8 y;
u8 x;
u8 tile;
unsigned f_cgb_pn : 3;
unsigned f_cgb_vram_bank : 1;
unsigned f_pn : 1;
unsigned f_x_flip : 1;
unsigned f_y_flip : 1;
unsigned f_bgp : 1;
u8 f_cgb_pn : 3;
u8 f_cgb_vram_bank : 1;
u8 f_pn : 1;
u8 f_x_flip : 1;
u8 f_y_flip : 1;
u8 f_bgp : 1;
} oam_entry;
typedef struct _oam_line_entry {
oam_entry entry;
struct _oam_line_entry *next;
} oam_line_entry;
typedef struct {
oam_entry oam_ram[40];
u8 vram[0x2000];
u8 line_sprite_count; // 0 to 10 sprites
oam_line_entry *line_sprites; //linked list of sprites
oam_line_entry line_entry_array[10]; //memory to use for list
u8 fetched_entry_count;
oam_entry fetched_entries[3]; //entries fetched during pipeline
u8 window_line;
pixel_fifo_context pfc;
u32 current_frame;
u32 line_ticks;
u32 *video_buffer;