~rabbits/nasu

6a01e0094d01dc987e5c478692aa4fb0a08e07c3 — Devine Lu Linvega 2 years ago 88e7f25
Fixed overflow issue
1 files changed, 4 insertions(+), 19 deletions(-)

M chr6.c
M chr6.c => chr6.c +4 -19
@@ 69,8 69,6 @@ dispt(Point* a, Point* b)
	return ((b->x - a->x) * (b->x - a->x)) + ((b->y - a->y) * (b->y - a->y));
}

/* Draw */

void
pixel(uint32_t* dst, Point p, int c)
{


@@ 88,7 86,7 @@ draw(uint32_t* dst, int id, int color)
	int ti = id / 64;
	int px = (ti / (HOR * VER)) * (8 * HOR);
	int tx = (ti % HOR) * 8;
	int ty = ((ti / HOR) * 8) % 128;
	int ty = ((ti / HOR) * 8);
	int odd = (ti + (ti / HOR + 2)) % 2 == 0;
	Point p;
	p.x = px + tx + (id % 8);


@@ 115,14 113,12 @@ redraw(uint32_t* dst)
	SDL_RenderPresent(gRenderer);
}

/* Chr */

void
write(int tx, int ty, int px, int py, int color)
{
	int id = tx + ty * HOR;
	int row = py + id * VER;
	if(id > HOR * VER)
	int row = py + (id * 16);
	if(row > SZ - 8)
		return;
	if(color == 0) {
		buffer[row] &= ~(1UL << (7 - px));


@@ 144,16 140,9 @@ edit(int x, int y, int color)
{
	if(x < 0 || y < 0 || x > 8 * HOR || y > 8 * VER)
		return;
	write(
	    x / (8),
	    y / (8),
	    x % 8,
	    y % 8,
	    color);
	write(x / 8, y / 8, x % 8, y % 8, color);
}

/* Brush */

int
patt(int x, int y, int mode, int size)
{


@@ 436,16 425,12 @@ main(int argc, char** argv)
	if(!init())
		return error("SDL", "failure");

	/* IO */

	if(argc > 1)
		load(argv[1]);
	else
		create();
	update(&brush);

	/* main loop */

	while(1) {
		int tick = SDL_GetTicks();
		SDL_Event event;