The screen is now a member of Ppu

This commit is contained in:
neauoire 2021-12-27 09:57:48 -08:00
parent fe75479fae
commit 4a223f91b5
3 changed files with 10 additions and 9 deletions

View File

@ -58,11 +58,15 @@ ppu_resize(Ppu *p, Uint16 width, Uint16 height)
Uint8 Uint8
*bg = realloc(p->bg.pixels, width * height), *bg = realloc(p->bg.pixels, width * height),
*fg = realloc(p->fg.pixels, width * height); *fg = realloc(p->fg.pixels, width * height);
Uint32
*screen = realloc(p->screen, width * height * sizeof(Uint32));
if(bg) p->bg.pixels = bg; if(bg) p->bg.pixels = bg;
if(fg) p->fg.pixels = fg; if(fg) p->fg.pixels = fg;
if(bg && fg) { if(screen) p->screen = screen;
if(bg && fg && screen) {
p->width = width; p->width = width;
p->height = height; p->height = height;
p->screen = screen;
ppu_clear(p, &p->bg); ppu_clear(p, &p->bg);
ppu_clear(p, &p->fg); ppu_clear(p, &p->fg);
} }

View File

@ -22,7 +22,7 @@ typedef struct Layer {
} Layer; } Layer;
typedef struct Ppu { typedef struct Ppu {
Uint32 palette[4]; Uint32 palette[4], *screen;
Uint16 width, height; Uint16 width, height;
Layer fg, bg; Layer fg, bg;
} Ppu; } Ppu;

View File

@ -44,7 +44,7 @@ static Ppu ppu;
static Apu apu[POLYPHONY]; static Apu apu[POLYPHONY];
static Device *devsystem, *devscreen, *devmouse, *devctrl, *devaudio0, *devconsole; static Device *devsystem, *devscreen, *devmouse, *devctrl, *devaudio0, *devconsole;
static Uint8 zoom = 1; static Uint8 zoom = 1;
static Uint32 *ppu_screen, stdin_event, audio0_event; static Uint32 stdin_event, audio0_event;
static int static int
clamp(int val, int min, int max) clamp(int val, int min, int max)
@ -118,15 +118,12 @@ set_size(Uint16 width, Uint16 height, int is_resize)
gRect.y = PAD; gRect.y = PAD;
gRect.w = ppu.width; gRect.w = ppu.width;
gRect.h = ppu.height; gRect.h = ppu.height;
if(!(ppu_screen = realloc(ppu_screen, ppu.width * ppu.height * sizeof(Uint32))))
return error("ppu_screen", "Memory failure");
memset(ppu_screen, 0, ppu.width * ppu.height * sizeof(Uint32));
if(gTexture != NULL) SDL_DestroyTexture(gTexture); if(gTexture != NULL) SDL_DestroyTexture(gTexture);
SDL_RenderSetLogicalSize(gRenderer, ppu.width + PAD * 2, ppu.height + PAD * 2); SDL_RenderSetLogicalSize(gRenderer, ppu.width + PAD * 2, ppu.height + PAD * 2);
gTexture = SDL_CreateTexture(gRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, ppu.width + PAD * 2, ppu.height + PAD * 2); gTexture = SDL_CreateTexture(gRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, ppu.width + PAD * 2, ppu.height + PAD * 2);
if(gTexture == NULL || SDL_SetTextureBlendMode(gTexture, SDL_BLENDMODE_NONE)) if(gTexture == NULL || SDL_SetTextureBlendMode(gTexture, SDL_BLENDMODE_NONE))
return error("gTexture", SDL_GetError()); return error("gTexture", SDL_GetError());
if(SDL_UpdateTexture(gTexture, NULL, ppu_screen, sizeof(Uint32)) != 0) if(SDL_UpdateTexture(gTexture, NULL, ppu.screen, sizeof(Uint32)) != 0)
return error("SDL_UpdateTexture", SDL_GetError()); return error("SDL_UpdateTexture", SDL_GetError());
if(is_resize) if(is_resize)
set_window_size(gWindow, (ppu.width + PAD * 2) * zoom, (ppu.height + PAD * 2) * zoom); set_window_size(gWindow, (ppu.width + PAD * 2) * zoom, (ppu.height + PAD * 2) * zoom);
@ -155,8 +152,8 @@ redraw(Uxn *u)
{ {
if(devsystem->dat[0xe]) if(devsystem->dat[0xe])
ppu_debug(&ppu, u->wst.dat, u->wst.ptr, u->rst.ptr, u->ram.dat); ppu_debug(&ppu, u->wst.dat, u->wst.ptr, u->rst.ptr, u->ram.dat);
ppu_redraw(&ppu, ppu_screen); ppu_redraw(&ppu, ppu.screen);
if(SDL_UpdateTexture(gTexture, &gRect, ppu_screen, ppu.width * sizeof(Uint32)) != 0) if(SDL_UpdateTexture(gTexture, &gRect, ppu.screen, ppu.width * sizeof(Uint32)) != 0)
error("SDL_UpdateTexture", SDL_GetError()); error("SDL_UpdateTexture", SDL_GetError());
SDL_RenderClear(gRenderer); SDL_RenderClear(gRenderer);
SDL_RenderCopy(gRenderer, gTexture, NULL, NULL); SDL_RenderCopy(gRenderer, gTexture, NULL, NULL);