mirror of
https://git.sr.ht/~rabbits/uxn
synced 2024-11-05 22:05:04 +00:00
Revert "Removed second texture of PPU"
This commit is contained in:
parent
ffe142ea91
commit
d5b2bd9895
3 changed files with 46 additions and 43 deletions
|
@ -41,11 +41,11 @@ readpixel(Uint8 *sprite, Uint8 h, Uint8 v)
|
|||
void
|
||||
clear(Ppu *p)
|
||||
{
|
||||
int i;
|
||||
for(i = p->height * p->width - 1; i >= 0; --i)
|
||||
p->rgba[i] = p->colors[0];
|
||||
for(i = p->height * p->width / 8 - 1; i >= 0; --i)
|
||||
p->index[i] = 0;
|
||||
int i, sz = p->height * p->width;
|
||||
for(i = 0; i < sz; ++i) {
|
||||
p->fg.pixels[i] = p->fg.colors[0];
|
||||
p->bg.pixels[i] = p->bg.colors[0];
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -57,28 +57,23 @@ putcolors(Ppu *p, Uint8 *addr)
|
|||
r = (*(addr + i / 2) >> (!(i % 2) << 2)) & 0x0f,
|
||||
g = (*(addr + 2 + i / 2) >> (!(i % 2) << 2)) & 0x0f,
|
||||
b = (*(addr + 4 + i / 2) >> (!(i % 2) << 2)) & 0x0f;
|
||||
p->colors[i] = 0xff000000 | (r << 20) | (r << 16) | (g << 12) | (g << 8) | (b << 4) | b;
|
||||
p->bg.colors[i] = 0xff000000 | (r << 20) | (r << 16) | (g << 12) | (g << 8) | (b << 4) | b;
|
||||
p->fg.colors[i] = 0xff000000 | (r << 20) | (r << 16) | (g << 12) | (g << 8) | (b << 4) | b;
|
||||
}
|
||||
for(i = 4; i < 16; ++i) p->colors[i] = p->colors[i / 4];
|
||||
p->fg.colors[0] = 0;
|
||||
clear(p);
|
||||
}
|
||||
|
||||
void
|
||||
putpixel(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color)
|
||||
putpixel(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color)
|
||||
{
|
||||
int rgba_i, index_i, shift_pixel, shift_layer;
|
||||
if(x >= p->width || y >= p->height)
|
||||
return;
|
||||
rgba_i = y * p->width + x;
|
||||
index_i = rgba_i >> 3;
|
||||
shift_pixel = (rgba_i & 0x7) * 4;
|
||||
shift_layer = shift_pixel + layer * 2;
|
||||
p->index[index_i] = (p->index[index_i] & ~(0x3 << shift_layer)) | (color << shift_layer);
|
||||
p->rgba[rgba_i] = p->colors[(p->index[index_i] >> shift_pixel) & 0xf];
|
||||
layer->pixels[y * p->width + x] = layer->colors[color];
|
||||
}
|
||||
|
||||
void
|
||||
puticn(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy)
|
||||
puticn(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy)
|
||||
{
|
||||
Uint16 v, h;
|
||||
for(v = 0; v < 8; v++)
|
||||
|
@ -94,7 +89,7 @@ puticn(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint
|
|||
}
|
||||
|
||||
void
|
||||
putchr(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy)
|
||||
putchr(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy)
|
||||
{
|
||||
Uint16 v, h;
|
||||
for(v = 0; v < 8; v++)
|
||||
|
@ -117,16 +112,16 @@ inspect(Ppu *p, Uint8 *stack, Uint8 ptr)
|
|||
Uint8 i, x, y, b;
|
||||
for(i = 0; i < 0x20; ++i) { /* memory */
|
||||
x = ((i % 8) * 3 + 1) * 8, y = (i / 8 + 1) * 8, b = stack[i];
|
||||
puticn(p, 0, x, y, font[(b >> 4) & 0xf], 1 + (ptr == i) * 0x7, 0, 0);
|
||||
puticn(p, 0, x + 8, y, font[b & 0xf], 1 + (ptr == i) * 0x7, 0, 0);
|
||||
puticn(p, &p->bg, x, y, font[(b >> 4) & 0xf], 1 + (ptr == i) * 0x7, 0, 0);
|
||||
puticn(p, &p->bg, x + 8, y, font[b & 0xf], 1 + (ptr == i) * 0x7, 0, 0);
|
||||
}
|
||||
for(x = 0; x < 0x20; ++x) {
|
||||
putpixel(p, 0, x, p->height / 2, 2);
|
||||
putpixel(p, 0, p->width - x, p->height / 2, 2);
|
||||
putpixel(p, 0, p->width / 2, p->height - x, 2);
|
||||
putpixel(p, 0, p->width / 2, x, 2);
|
||||
putpixel(p, 0, p->width / 2 - 16 + x, p->height / 2, 2);
|
||||
putpixel(p, 0, p->width / 2, p->height / 2 - 16 + x, 2);
|
||||
putpixel(p, &p->bg, x, p->height / 2, 2);
|
||||
putpixel(p, &p->bg, p->width - x, p->height / 2, 2);
|
||||
putpixel(p, &p->bg, p->width / 2, p->height - x, 2);
|
||||
putpixel(p, &p->bg, p->width / 2, x, 2);
|
||||
putpixel(p, &p->bg, p->width / 2 - 16 + x, p->height / 2, 2);
|
||||
putpixel(p, &p->bg, p->width / 2, p->height / 2 - 16 + x, 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,9 +132,9 @@ initppu(Ppu *p, Uint8 hor, Uint8 ver)
|
|||
p->ver = ver;
|
||||
p->width = 8 * p->hor;
|
||||
p->height = 8 * p->ver;
|
||||
if(!(p->index = malloc(p->width * p->height / 8 * sizeof(Uint32))))
|
||||
if(!(p->bg.pixels = malloc(p->width * p->height * sizeof(Uint32))))
|
||||
return 0;
|
||||
if(!(p->rgba = malloc(p->width * p->height * sizeof(Uint32))))
|
||||
if(!(p->fg.pixels = malloc(p->width * p->height * sizeof(Uint32))))
|
||||
return 0;
|
||||
clear(p);
|
||||
return 1;
|
||||
|
|
|
@ -18,17 +18,17 @@ typedef unsigned short Uint16;
|
|||
typedef unsigned int Uint32;
|
||||
|
||||
typedef struct Layer {
|
||||
Uint32 *pixels;
|
||||
Uint32 *pixels, colors[4];
|
||||
} Layer;
|
||||
|
||||
typedef struct Ppu {
|
||||
Uint32 *rgba, *index, colors[16];
|
||||
Uint16 hor, ver, width, height;
|
||||
Layer fg, bg;
|
||||
} Ppu;
|
||||
|
||||
int initppu(Ppu *p, Uint8 hor, Uint8 ver);
|
||||
void putcolors(Ppu *p, Uint8 *addr);
|
||||
void putpixel(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color);
|
||||
void puticn(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy);
|
||||
void putchr(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy);
|
||||
void putpixel(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color);
|
||||
void puticn(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy);
|
||||
void putchr(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy);
|
||||
void inspect(Ppu *p, Uint8 *stack, Uint8 ptr);
|
||||
|
|
30
src/uxnemu.c
30
src/uxnemu.c
|
@ -20,7 +20,7 @@ WITH REGARD TO THIS SOFTWARE.
|
|||
static SDL_AudioDeviceID audio_id;
|
||||
static SDL_Window *gWindow;
|
||||
static SDL_Renderer *gRenderer;
|
||||
static SDL_Texture *gTexture;
|
||||
static SDL_Texture *fgTexture, *bgTexture;
|
||||
static SDL_Rect gRect;
|
||||
static Ppu ppu;
|
||||
static Apu apu[POLYPHONY];
|
||||
|
@ -60,9 +60,11 @@ redraw(Uxn *u)
|
|||
{
|
||||
if(debug)
|
||||
inspect(&ppu, u->wst.dat, u->wst.ptr);
|
||||
SDL_UpdateTexture(gTexture, &gRect, ppu.rgba, ppu.width * sizeof(Uint32));
|
||||
SDL_UpdateTexture(bgTexture, &gRect, ppu.bg.pixels, ppu.width * sizeof(Uint32));
|
||||
SDL_UpdateTexture(fgTexture, &gRect, ppu.fg.pixels, ppu.width * sizeof(Uint32));
|
||||
SDL_RenderClear(gRenderer);
|
||||
SDL_RenderCopy(gRenderer, gTexture, NULL, NULL);
|
||||
SDL_RenderCopy(gRenderer, bgTexture, NULL, NULL);
|
||||
SDL_RenderCopy(gRenderer, fgTexture, NULL, NULL);
|
||||
SDL_RenderPresent(gRenderer);
|
||||
reqdraw = 0;
|
||||
}
|
||||
|
@ -85,11 +87,13 @@ togglezoom(Uxn *u)
|
|||
void
|
||||
quit(void)
|
||||
{
|
||||
free(ppu.rgba);
|
||||
free(ppu.index);
|
||||
free(ppu.fg.pixels);
|
||||
free(ppu.bg.pixels);
|
||||
SDL_UnlockAudioDevice(audio_id);
|
||||
SDL_DestroyTexture(gTexture);
|
||||
gTexture = NULL;
|
||||
SDL_DestroyTexture(bgTexture);
|
||||
bgTexture = NULL;
|
||||
SDL_DestroyTexture(fgTexture);
|
||||
fgTexture = NULL;
|
||||
SDL_DestroyRenderer(gRenderer);
|
||||
gRenderer = NULL;
|
||||
SDL_DestroyWindow(gWindow);
|
||||
|
@ -119,10 +123,14 @@ init(void)
|
|||
if(gRenderer == NULL)
|
||||
return error("Renderer", SDL_GetError());
|
||||
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)
|
||||
bgTexture = SDL_CreateTexture(gRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, ppu.width + PAD * 2, ppu.height + PAD * 2);
|
||||
if(bgTexture == NULL || SDL_SetTextureBlendMode(bgTexture, SDL_BLENDMODE_NONE))
|
||||
return error("Texture", SDL_GetError());
|
||||
SDL_UpdateTexture(gTexture, NULL, ppu.rgba, 4);
|
||||
fgTexture = SDL_CreateTexture(gRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, ppu.width + PAD * 2, ppu.height + PAD * 2);
|
||||
if(fgTexture == NULL || SDL_SetTextureBlendMode(fgTexture, SDL_BLENDMODE_BLEND))
|
||||
return error("Texture", SDL_GetError());
|
||||
SDL_UpdateTexture(bgTexture, NULL, ppu.bg.pixels, 4);
|
||||
SDL_UpdateTexture(fgTexture, NULL, ppu.fg.pixels, 4);
|
||||
SDL_StartTextInput();
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
SDL_zero(as);
|
||||
|
@ -224,7 +232,7 @@ screen_talk(Device *d, Uint8 b0, Uint8 w)
|
|||
Uint16 x = mempeek16(d->dat, 0x8);
|
||||
Uint16 y = mempeek16(d->dat, 0xa);
|
||||
Uint8 *addr = &d->mem[mempeek16(d->dat, 0xc)];
|
||||
Uint8 layer = (d->dat[0xe] >> 4) & 0x1;
|
||||
Layer *layer = d->dat[0xe] >> 4 & 0x1 ? &ppu.fg : &ppu.bg;
|
||||
Uint8 mode = d->dat[0xe] >> 5;
|
||||
if(!mode)
|
||||
putpixel(&ppu, layer, x, y, d->dat[0xe] & 0x3);
|
||||
|
|
Loading…
Reference in a new issue