From ec9226e144e3208e682350f3832862e48aa9e24f Mon Sep 17 00:00:00 2001 From: Matthew Laux Date: Mon, 20 Jun 2022 19:52:54 -0500 Subject: [PATCH] init lcd pixels, fix compile warnings --- cli/emulator.c | 4 +++- src/cpu.c | 6 ++++++ src/lcd.c | 7 +++++++ src/lcd.h | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cli/emulator.c b/cli/emulator.c index 92e2e3b..5655363 100644 --- a/cli/emulator.c +++ b/cli/emulator.c @@ -22,7 +22,9 @@ int main(int argc, char *argv[]) if (!rom_load(&rom, argv[1])) { printf("error loading rom\n"); return 1; - } + } + + lcd_new(&lcd); // this might be too much abstraction but it'll let me // test the cpu, rom, and dmg independently and use the cpu diff --git a/src/cpu.c b/src/cpu.c index 7b5c6ae..e57cb33 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -265,6 +265,9 @@ static u8 read_reg(struct cpu *cpu, int index) case 7: return cpu->a; default: cpu_panic(cpu); } + + // unreachable + return 0; } static u8 write_reg(struct cpu *cpu, int index, u8 val) @@ -280,6 +283,9 @@ static u8 write_reg(struct cpu *cpu, int index, u8 val) case 7: cpu->a = val; break; default: cpu_panic(cpu); } + + // unreachable + return 0; } static void extended_insn(struct cpu *cpu, u8 insn) diff --git a/src/lcd.c b/src/lcd.c index 21b682e..c12c70a 100644 --- a/src/lcd.c +++ b/src/lcd.c @@ -1,4 +1,5 @@ #include +#include #include "types.h" #include "lcd.h" @@ -13,6 +14,12 @@ static void clear_bit(struct lcd *lcd, u16 addr, u8 bit) lcd_write(lcd, addr, lcd_read(lcd, addr) & ~(1 << bit)); } +void lcd_new(struct lcd *lcd) +{ + // todo < 8 bpp + lcd->pixels = malloc(LCD_WIDTH * LCD_HEIGHT); +} + u8 lcd_is_valid_addr(u16 addr) { return addr >= REG_LCD_BASE && addr <= REG_LCD_LAST; diff --git a/src/lcd.h b/src/lcd.h index ccb2326..84735aa 100644 --- a/src/lcd.h +++ b/src/lcd.h @@ -30,6 +30,7 @@ struct lcd { u8 *pixels; }; +void lcd_new(struct lcd *lcd); u8 lcd_is_valid_addr(u16 addr); u8 lcd_read(struct lcd *lcd, u16 addr); void lcd_write(struct lcd *lcd, u16 addr, u8 value);