|
|
|
|
@ -55,10 +55,11 @@ draw(uint32_t* dst, int id, int color)
|
|
|
|
|
int px = (ti / 256) * 128; |
|
|
|
|
int tx = (ti % 16) * 8; |
|
|
|
|
int ty = ((ti / 16) * 8) % 128; |
|
|
|
|
int odd = (ti + (ti / 16 + 2)) % 2 == 0; |
|
|
|
|
Point p; |
|
|
|
|
p.x = px + tx + (id % 8); |
|
|
|
|
p.y = ty + ((id % 64) / 8); |
|
|
|
|
pixel(dst, p, colors[color]); |
|
|
|
|
pixel(dst, p, colors[odd && color == 0 ? 3 : color]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
@ -111,6 +112,7 @@ edit(Brush* b)
|
|
|
|
|
(p1.x / ZOOM) % 8, |
|
|
|
|
(p1.y / ZOOM) % 8, |
|
|
|
|
b->color); |
|
|
|
|
SDL_SetWindowTitle(gWindow, "nasu*"); |
|
|
|
|
redraw(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -127,12 +129,16 @@ erase(Brush* b)
|
|
|
|
|
buffer[(id * 16) + i] = 0x00; |
|
|
|
|
buffer[(id * 16) + i + 8] = 0x00; |
|
|
|
|
} |
|
|
|
|
SDL_SetWindowTitle(gWindow, "nasu*"); |
|
|
|
|
redraw(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void export(uint32_t* dst) |
|
|
|
|
void |
|
|
|
|
save(void) |
|
|
|
|
{ |
|
|
|
|
/* TODO: chr file export */ |
|
|
|
|
fwrite(buffer, sizeof(buffer), 1, |
|
|
|
|
fopen("output.chr", "wb")); |
|
|
|
|
SDL_SetWindowTitle(gWindow, "nasu"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int |
|
|
|
|
@ -157,7 +163,7 @@ quit(void)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
handle_mouse(SDL_Event* event, Brush* b) |
|
|
|
|
mousehandler(SDL_Event* event, Brush* b) |
|
|
|
|
{ |
|
|
|
|
switch(event->type) { |
|
|
|
|
case SDL_MOUSEBUTTONUP: |
|
|
|
|
@ -179,14 +185,14 @@ handle_mouse(SDL_Event* event, Brush* b)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
handle_keypress(SDL_Event* event, Brush* b) |
|
|
|
|
keyhandler(SDL_Event* event, Brush* b) |
|
|
|
|
{ |
|
|
|
|
switch(event->key.keysym.sym) { |
|
|
|
|
case SDLK_ESCAPE: |
|
|
|
|
quit(); |
|
|
|
|
break; |
|
|
|
|
case SDLK_e: |
|
|
|
|
export(pixels); |
|
|
|
|
save(); |
|
|
|
|
break; |
|
|
|
|
case SDLK_1: |
|
|
|
|
b->color = 0; |
|
|
|
|
@ -204,14 +210,26 @@ handle_keypress(SDL_Event* event, Brush* b)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int |
|
|
|
|
load(FILE* f) |
|
|
|
|
load(char* path) |
|
|
|
|
{ |
|
|
|
|
FILE* f = fopen(path, "rb"); |
|
|
|
|
if(f == NULL) |
|
|
|
|
return error("Load", "Invalid input file"); |
|
|
|
|
if(!fread(buffer, sizeof(buffer), 1, f)) |
|
|
|
|
return error("Invalid size file", ""); |
|
|
|
|
return error("Load", "Invalid file size"); |
|
|
|
|
redraw(); |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
create(void) |
|
|
|
|
{ |
|
|
|
|
int i; |
|
|
|
|
for(i = 0; i < 4096; ++i) |
|
|
|
|
buffer[i] = 0x00; |
|
|
|
|
redraw(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int |
|
|
|
|
init(void) |
|
|
|
|
{ |
|
|
|
|
@ -250,20 +268,17 @@ main(int argc, char** argv)
|
|
|
|
|
{ |
|
|
|
|
int ticknext = 0; |
|
|
|
|
Brush brush; |
|
|
|
|
FILE* f; |
|
|
|
|
brush.color = 1; |
|
|
|
|
|
|
|
|
|
if(!init()) |
|
|
|
|
return error("SDL", "failure"); |
|
|
|
|
|
|
|
|
|
if(argc < 2) |
|
|
|
|
return error("Missing input file", ""); |
|
|
|
|
|
|
|
|
|
f = fopen(argv[1], "rb"); |
|
|
|
|
|
|
|
|
|
if(f == NULL) |
|
|
|
|
return error("Invalid input file.", ""); |
|
|
|
|
/* IO */ |
|
|
|
|
|
|
|
|
|
load(f); |
|
|
|
|
if(argc > 1) |
|
|
|
|
load(argv[1]); |
|
|
|
|
else |
|
|
|
|
create(); |
|
|
|
|
|
|
|
|
|
/* main loop */ |
|
|
|
|
|
|
|
|
|
@ -281,9 +296,9 @@ main(int argc, char** argv)
|
|
|
|
|
if(event.type == SDL_MOUSEBUTTONUP || |
|
|
|
|
event.type == SDL_MOUSEBUTTONDOWN || |
|
|
|
|
event.type == SDL_MOUSEMOTION) { |
|
|
|
|
handle_mouse(&event, &brush); |
|
|
|
|
mousehandler(&event, &brush); |
|
|
|
|
} else if(event.type == SDL_KEYDOWN) |
|
|
|
|
handle_keypress(&event, &brush); |
|
|
|
|
keyhandler(&event, &brush); |
|
|
|
|
} |
|
|
|
|
SDL_RenderClear(gRenderer); |
|
|
|
|
SDL_RenderCopy(gRenderer, gTexture, NULL, NULL); |
|
|
|
|
|