endif
.PHONY: all
-all: data $(bin)
+all: $(bin)
$(bin): $(obj) imago
$(CC) -o $@ $(obj) $(LDFLAGS)
#include "game.h"
#include "screens.h"
+#include "sprite.h"
int fb_width, fb_height;
long fb_size;
void (*draw)(void);
void (*key_event)(int key, int pressed);
+static struct sprites dbgfont;
+
int init(int argc, char **argv)
{
+ if(load_sprites(&dbgfont, "data/dbgfont.spr") == -1) {
+ return -1;
+ }
if(intro_init() == -1) {
return -1;
}
menu_cleanup();
}
-void cs_puts_font(cs_font_func csfont, int sz, void *fb, int x, int y, const char *str)
+void dbg_print(void *fb, int x, int y, const char *str)
{
+ uint16_t *dest = (uint16_t*)fb + y * fb_width + x;
+
while(*str) {
int c = *str++;
if(c > ' ' && c < 128) {
- csfont(fb, x, y, c - ' ');
+ draw_sprite(dest, fb_width * 2, &dbgfont, c - ' ');
}
- x += sz;
+ dest += 8;
}
}
void game_quit(void);
-/* compiled sprites available */
-typedef void (*cs_font_func)(void *, int, int, int);
-void cs_dbgfont(void *fb, int x, int y, int idx);
-
-/* helper to print text with cs_font */
-void cs_puts_font(cs_font_func csfont, int sz, void *fb, int x, int y, const char *str);
-
-#define cs_dputs(fb, x, y, str) cs_puts_font(cs_dbgfont, 9, fb, x, y, str)
+void dbg_print(void *fb, int x, int y, const char *str);
#endif /* GAME_H_ */
}
}
- //cs_dputs(fb_pixels, 10, 10, "foo");
+ dbg_print(fb_pixels, 10, 10, "foo");
blit_frame(fb_pixels, 1);
}
xsz = FB_WIDTH * fbscale;
ysz = FB_HEIGHT * fbscale;
- fb_width = xsz;
- fb_height = ysz;
+ fb_width = FB_WIDTH;
+ fb_height = FB_HEIGHT;
fb_size = FB_WIDTH * FB_HEIGHT * FB_BPP / 8;
if(!(fb_buf = malloc(fb_size + FB_WIDTH * 4))) {
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include <assert.h>
#include "inttypes.h"
#include "sprite.h"
#include "util.h"
+
+#define SOP_OP(op) ((op) & 0xff)
+#define SOP_LEN(op) ((op) >> 16)
+
#pragma pack (push, 1)
struct file_header {
char magic[8];
free(spr->ops);
return -1;
}
+
+void draw_sprite(void *dest, int fbpitch, struct sprites *ss, int idx)
+{
+ struct sprite_op *sop = ss->sprites[idx].ops;
+ unsigned char *fbptr = dest;
+ int xoffs = 0;
+
+ for(;;) {
+ assert((xoffs & 1) == 0);
+ switch(sop->op) {
+ case SOP_END:
+ return;
+ case SOP_ENDL:
+ fbptr += fbpitch;
+ xoffs = 0;
+ break;
+ case SOP_SKIP:
+ xoffs += sop->size;
+ break;
+ case SOP_COPY:
+ memcpy(fbptr + xoffs, sop->data, sop->size);
+ xoffs += sop->size;
+ break;
+ default:
+ break;
+ }
+ sop++;
+ }
+}
SOP_COPY
};
-#define SOP_OP(op) ((op) & 0xff)
-#define SOP_LEN(op) ((op) >> 16)
-
struct sprite_op {
unsigned char op;
unsigned short size;
int load_sprites(struct sprites *ss, const char *fname);
+void draw_sprite(void *dest, int fbpitch, struct sprites *ss, int idx);
+
#endif /* SPRITE_H_ */
int rlesprite(struct image *img, int x, int y, int xsz, int ysz)
{
int i, j, numops, mode, new_mode, start, skip_acc, pixsz = img->bpp / 8;
- unsigned char *pptr = img->pixels + y * img->scansz + x * pixsz;
+ unsigned char *scanptr, *pptr;
struct csop *ops, *optr, endop = {0};
+ pptr = img->pixels + y * img->scansz + x * pixsz;
+
ops = optr = alloca((xsz + 1) * ysz * sizeof *ops);
for(i=0; i<ysz; i++) {
}
numops = optr - ops;
- pptr = img->pixels + y * img->scansz + x * img->bpp / 8;
+ scanptr = pptr = img->pixels + y * img->scansz + x * img->bpp / 8;
optr = ops;
skip_acc = 0;
/* maybe at some point combine multiple endl into yskips? meh */
fwrite(optr, sizeof *optr, 1, outfp);
skip_acc = 0;
- pptr += img->scansz - xsz * pixsz;
+ scanptr += img->scansz;
+ pptr = scanptr;
break;
case CSOP_COPY:
fwrite(optr, sizeof *optr, 1, outfp);
fwrite(pptr, pixsz, optr->len, outfp);
- pptr += optr->len;
+ pptr += optr->len * pixsz;
break;
default: