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
*bg = realloc(p->bg.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(fg) p->fg.pixels = fg;
if(bg && fg) {
if(screen) p->screen = screen;
if(bg && fg && screen) {
p->width = width;
p->height = height;
p->screen = screen;
ppu_clear(p, &p->bg);
ppu_clear(p, &p->fg);
}

View File

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

View File

@ -44,7 +44,7 @@ static Ppu ppu;
static Apu apu[POLYPHONY];
static Device *devsystem, *devscreen, *devmouse, *devctrl, *devaudio0, *devconsole;
static Uint8 zoom = 1;
static Uint32 *ppu_screen, stdin_event, audio0_event;
static Uint32 stdin_event, audio0_event;
static int
clamp(int val, int min, int max)
@ -118,15 +118,12 @@ set_size(Uint16 width, Uint16 height, int is_resize)
gRect.y = PAD;
gRect.w = ppu.width;
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);
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);
if(gTexture == NULL || SDL_SetTextureBlendMode(gTexture, SDL_BLENDMODE_NONE))
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());
if(is_resize)
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])
ppu_debug(&ppu, u->wst.dat, u->wst.ptr, u->rst.ptr, u->ram.dat);
ppu_redraw(&ppu, ppu_screen);
if(SDL_UpdateTexture(gTexture, &gRect, ppu_screen, ppu.width * sizeof(Uint32)) != 0)
ppu_redraw(&ppu, ppu.screen);
if(SDL_UpdateTexture(gTexture, &gRect, ppu.screen, ppu.width * sizeof(Uint32)) != 0)
error("SDL_UpdateTexture", SDL_GetError());
SDL_RenderClear(gRenderer);
SDL_RenderCopy(gRenderer, gTexture, NULL, NULL);