uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit c0e42f132291542d8c275efea5fc09ede4f83ee9
parent b6fe4302d11667e1a6c171530b1fcbd69863a04d
Author: Andrew Alderwick <andrew@alderwick.co.uk>
Date:   Mon, 20 Sep 2021 22:32:42 +0100

Switched to faster unsigned ints for PPU memory

Diffstat:
Msrc/devices/ppu.c | 17++++++++---------
Msrc/devices/ppu.h | 12++++++++----
Msrc/uxnemu.c | 5+++--
3 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/src/devices/ppu.c b/src/devices/ppu.c @@ -23,22 +23,22 @@ static void ppu_clear(Ppu *p) { int i; - for(i = 0; i < p->width / 2 * p->height; ++i) + for(i = 0; i < p->stride * p->height; ++i) p->dat[i] = 0; } -int +unsigned int ppu_pixel(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 color) { - unsigned int i = (x + y * p->width) / 2, shift = (x % 2) * 4; - int ret = p->dat[i]; + unsigned int i = x / PPW + y * p->stride, shift = x % PPW * 4; + unsigned int ret = p->dat[i]; if(fg) shift += 2; p->dat[i] &= ~(3 << shift); p->dat[i] |= color << shift; return ret ^ p->dat[i]; } -int +unsigned int ppu_1bpp(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy) { Uint16 v, h; @@ -56,7 +56,7 @@ ppu_1bpp(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 f return ret; } -int +unsigned int ppu_2bpp(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy) { Uint16 v, h; @@ -81,11 +81,10 @@ ppu_2bpp(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 f int ppu_set_size(Ppu *p, Uint16 width, Uint16 height) { - /* round width up to nearest multiple of 2 */ - width += width % 2; p->width = width; + p->stride = (width + PPW - 1) / PPW; p->height = height; - p->dat = realloc(p->dat, p->width / 2 * p->height); + p->dat = realloc(p->dat, p->stride * p->height * sizeof(unsigned int)); if(p->dat == NULL) return 0; ppu_clear(p); return 1; diff --git a/src/devices/ppu.h b/src/devices/ppu.h @@ -13,16 +13,20 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ +/* pixels per word in ppu.dat */ + +#define PPW (sizeof(unsigned int) * 2) + typedef unsigned char Uint8; typedef unsigned short Uint16; typedef unsigned int Uint32; typedef struct Ppu { Uint16 width, height; - Uint8 *dat; + unsigned int *dat, stride; } Ppu; int ppu_set_size(Ppu *p, Uint16 width, Uint16 height); -int ppu_pixel(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 color); -int ppu_1bpp(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy); -int ppu_2bpp(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy); +unsigned int ppu_pixel(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 color); +unsigned int ppu_1bpp(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy); +unsigned int ppu_2bpp(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy); diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -38,7 +38,8 @@ static Apu apu[POLYPHONY]; static Device *devsystem, *devscreen, *devmouse, *devctrl, *devaudio0, *devconsole; static Uint32 *ppu_screen, stdin_event, audio0_event, palette[4]; -static Uint8 zoom = 1, reqdraw = 0; +static Uint8 zoom = 1; +static unsigned int reqdraw = 0; static Uint8 font[][8] = { {0x00, 0x7c, 0x82, 0x82, 0x82, 0x82, 0x82, 0x7c}, @@ -114,7 +115,7 @@ inspect(Ppu *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory) static Uint8 get_pixel(int x, int y) { - unsigned int i = (x + y * ppu.width) / 2, shift = (x % 2) * 4; + unsigned int i = x / PPW + y * ppu.stride, shift = x % PPW * 4; return (ppu.dat[i] >> shift) & 0xf; }