correct rendering

This commit is contained in:
IoIxD 2026-03-10 20:06:11 -07:00
commit fe80b43264
2 changed files with 13 additions and 15 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
*.zip
*.gb
milskoboy

25
main.c
View file

@ -1,5 +1,4 @@
#define ENABLE_SOUND 0
#define ENABLE_LCD 1
#include "peanut_gb.h"
@ -16,7 +15,7 @@
struct priv_t {
uint8_t *rom;
uint8_t *cart_ram;
uint8_t *fb;
uint8_t fb[LCD_WIDTH * LCD_HEIGHT * 4];
MwWidget *win;
MwWidget *fb_widget;
@ -37,8 +36,6 @@ int mfb_open(const char *title, int width, int height) {
priv.px = NULL;
priv.fb = malloc(LCD_WIDTH * LCD_HEIGHT * 4);
// XPixmapFormatValues *formats;
// XSetWindowAttributes windowAttributes;
// XSizeHints sizeHints;
@ -135,8 +132,10 @@ static int processEvents() {
}
int mfb_update(void *buffer) {
if (processEvents() < 0)
return -1;
// if (MwPending(priv.win)) {
// }
MwStep(priv.win);
if (priv.px == NULL) {
priv.px = MwLoadRaw(priv.win, buffer, LCD_WIDTH, LCD_HEIGHT);
@ -146,8 +145,6 @@ int mfb_update(void *buffer) {
MwVaApply(priv.fb_widget, MwNpixmap, priv.px, NULL);
printf("test\n");
return 0;
}
@ -228,17 +225,18 @@ void gb_error(struct gb_s *gb, const enum gb_error_e gb_err,
exit(EXIT_FAILURE);
}
#if ENABLE_LCD
/**
* Draws scanline into framebuffer.
*/
void lcd_draw_line(struct gb_s *gb, const uint8_t pixels[160],
const uint_fast8_t line) {
struct priv_t *priv = gb->direct.priv;
const MwU8 palette[] = {0xFF, 0xA5, 0x52, 0x00};
const uint16_t palette[3][4] = {{0xFF, 0xA5, 0x52, 0x00},
{0xFF, 0xA5, 0x52, 0x00},
{0xFF, 0xA5, 0x52, 0x00}};
for (unsigned int x = 0; x < LCD_WIDTH; x++) {
MwU8 p = (pixels[x] & LCD_PALETTE_ALL);
MwU8 p = palette[(pixels[x] & LCD_PALETTE_ALL) >> 4][pixels[x] & 3];
int i = ((line * LCD_WIDTH) + x) * 4;
priv->fb[i] = p;
@ -247,7 +245,6 @@ void lcd_draw_line(struct gb_s *gb, const uint8_t pixels[160],
priv->fb[i + 3] = 255;
}
}
#endif
int main(int argc, char **argv) {
/* Must be freed */
@ -282,10 +279,8 @@ int main(int argc, char **argv) {
priv.cart_ram = malloc(gb_get_save_size(&gb));
#if ENABLE_LCD
gb_init_lcd(&gb, &lcd_draw_line);
// gb.direct.interlace = true;
#endif
if (!mfb_open("Peanut-minifb", LCD_WIDTH, LCD_HEIGHT))
return EXIT_FAILURE;
@ -330,4 +325,4 @@ int main(int argc, char **argv) {
free(priv.rom);
return EXIT_SUCCESS;
}
}