beginning ppu
This commit is contained in:
@ -15,5 +15,6 @@ typedef uint64_t u64;
|
||||
#define BETWEEN(a, b, c) ((a >= b) && (a <= c))
|
||||
|
||||
void delay(u32 ms);
|
||||
u32 get_ticks();
|
||||
|
||||
#define NO_IMPL { fprintf(stderr, "NOT YET IMPLEMENTED\n"); exit(-5); }
|
8
include/dma.h
Normal file
8
include/dma.h
Normal file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <common.h>
|
||||
|
||||
void dma_start(u8 start);
|
||||
void dma_tick();
|
||||
|
||||
bool dma_transferring();
|
60
include/lcd.h
Normal file
60
include/lcd.h
Normal file
@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
#include <common.h>
|
||||
|
||||
typedef struct {
|
||||
//registers
|
||||
u8 lcdc;
|
||||
u8 lcds;
|
||||
u8 scroll_y;
|
||||
u8 scroll_x;
|
||||
u8 ly;
|
||||
u8 ly_compare;
|
||||
u8 dma;
|
||||
u8 bg_palette;
|
||||
u8 obj_palette[2];
|
||||
u8 win_y;
|
||||
u8 win_x;
|
||||
|
||||
//other data...
|
||||
u32 bg_colors[4];
|
||||
u32 sp1_colors[4];
|
||||
u32 sp2_colors[4];
|
||||
} lcd_context;
|
||||
|
||||
typedef enum {
|
||||
MODE_HBLANK,
|
||||
MODE_VBLANK,
|
||||
MODE_OAM,
|
||||
MODE_XFER
|
||||
} lcd_mode;
|
||||
|
||||
lcd_context *lcd_get_context();
|
||||
|
||||
#define LCDC_BGW_ENABLE (BIT(lcd_get_context()->lcdc, 0))
|
||||
#define LCDC_OBJ_ENABLE (BIT(lcd_get_context()->lcdc, 1))
|
||||
#define LCDC_OBJ_HEIGHT (BIT(lcd_get_context()->lcdc, 2) ? 16 : 8)
|
||||
#define LCDC_BG_MAP_AREA (BIT(lcd_get_context()->lcdc, 3) ? 0x9C00 : 0x9800)
|
||||
#define LCDC_BGW_DATA_AREA (BIT(lcd_get_context()->lcdc, 4) ? 0x8000 : 0x8800)
|
||||
#define LCDC_WIN_ENABLE (BIT(lcd_get_context()->lcdc, 5))
|
||||
#define LCDC_WIN_MAP_AREA (BIT(lcd_get_context()->lcdc, 6) ? 0x9C00 : 0x9800)
|
||||
#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_LYC (BIT(lcd_get_context()->lcds, 2))
|
||||
#define LCDS_LYC_SET(b) BIT_SET(lcd_get_context()->lcds, 2, b)
|
||||
|
||||
typedef enum {
|
||||
SS_HBLANK = (1 << 3),
|
||||
SS_VBLANK = (1 << 4),
|
||||
SS_OAM = (1 << 5),
|
||||
SS_LYC = (1 << 6)
|
||||
} stat_src;
|
||||
|
||||
#define LCDS_STAT_INT(src) (lcd_get_context()->lcds & src)
|
||||
|
||||
void lcd_init();
|
||||
|
||||
u8 lcd_read(u16 address);
|
||||
void lcd_write(u16 address, u8 value);
|
@ -2,5 +2,40 @@
|
||||
|
||||
#include <common.h>
|
||||
|
||||
static const LINES_PER_FRAME = 154;
|
||||
static const TICKS_PER_LINE = 456;
|
||||
static const YRES = 144;
|
||||
static const XRES = 160;
|
||||
|
||||
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;
|
||||
} oam_entry;
|
||||
|
||||
typedef struct {
|
||||
oam_entry oam_ram[40];
|
||||
u8 vram[0x2000];
|
||||
|
||||
u32 current_frame;
|
||||
u32 line_ticks;
|
||||
u32 *video_buffer;
|
||||
} ppu_context;
|
||||
|
||||
void ppu_init();
|
||||
void ppu_tick();
|
||||
void ppu_tick();
|
||||
|
||||
void ppu_oam_write(u16 address, u8 value);
|
||||
u8 ppu_oam_read(u16 address);
|
||||
|
||||
void ppu_vram_write(u16 address, u8 value);
|
||||
u8 ppu_vram_read(u16 address);
|
||||
|
||||
ppu_context *ppu_get_context();
|
8
include/ppu_sm.h
Normal file
8
include/ppu_sm.h
Normal file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <common.h>
|
||||
|
||||
void ppu_mode_oam();
|
||||
void ppu_mode_xfer();
|
||||
void ppu_mode_vblank();
|
||||
void ppu_mode_hblank();
|
@ -2,5 +2,17 @@
|
||||
|
||||
#include <common.h>
|
||||
|
||||
typedef struct {
|
||||
u16 div;
|
||||
u8 tima;
|
||||
u8 tma;
|
||||
u8 tac;
|
||||
} timer_context;
|
||||
|
||||
void timer_init();
|
||||
void timer_tick();
|
||||
void timer_tick();
|
||||
|
||||
void timer_write(u16 address, u8 value);
|
||||
u8 timer_read(u16 address);
|
||||
|
||||
timer_context *timer_get_context();
|
@ -6,4 +6,5 @@ static const int SCREEN_WIDTH = 1024;
|
||||
static const int SCREEN_HEIGHT = 768;
|
||||
|
||||
void ui_init();
|
||||
void ui_handle_events();
|
||||
void ui_handle_events();
|
||||
void ui_update();
|
Reference in New Issue
Block a user