convert external image for test tile and blit hardcoded grid
authorJohn Tsiombikas <nuclear@member.fsf.org>
Thu, 26 Jul 2018 00:03:25 +0000 (03:03 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Thu, 26 Jul 2018 00:03:25 +0000 (03:03 +0300)
.gitignore
Makefile.amiga
src/data.h [new file with mode: 0644]
src/data.s [new file with mode: 0644]
src/game.c
tools/conv_gimp [new file with mode: 0755]
tools/conv_gimp.c [new file with mode: 0644]

index 52d0701..825ef7d 100644 (file)
@@ -5,3 +5,5 @@
 *.bin
 *.elf
 link.map
+*.img
+*.pal
index 89a02c3..c6fbfbd 100644 (file)
@@ -1,6 +1,7 @@
 src = $(wildcard src/*.c) \
          $(wildcard src/amiga/*.c)
-asrc = $(wildcard src/amiga/*.s) \
+asrc = $(wildcard src/*.s) \
+          $(wildcard src/amiga/*.s) \
           $(wildcard src/amiga/libc/*.s)
 obj = $(src:.c=.o) $(asrc:.s=.o) 
 dep = $(src:.c=.d)
diff --git a/src/data.h b/src/data.h
new file mode 100644 (file)
index 0000000..7cb952a
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef DATA_H_
+#define DATA_H_
+
+extern unsigned char test_tile[];
+extern unsigned char test_tile_mask[];
+
+#endif /* DATA_H_ */
diff --git a/src/data.s b/src/data.s
new file mode 100644 (file)
index 0000000..5a6f27a
--- /dev/null
@@ -0,0 +1,9 @@
+       .data
+
+       .global test_tile
+test_tile:
+       .incbin "data/test_tile.img"
+
+       .global test_tile_mask
+test_tile_mask:
+       .incbin "data/test_tile_mask.img"
index a4dc4c7..97c1895 100644 (file)
@@ -1,40 +1,54 @@
 #include <string.h>
 #include "game.h"
-#include "data_test.h"
 #include "gfx.h"
+#include "data.h"
 
 #include "hwregs.h"    /* XXX */
 
-#define TILE_W 32
-#define TILE_H 16
+#define TILE_W 64
+#define TILE_H 32
 
 void draw_tile(int tid, int x, int y, int light);
-void convert_tile_data(unsigned char *dest, const char *src);
 
-static unsigned char test_tiles[2][TILE_W * TILE_H / 8 * NBPL];
-static unsigned char tile_mask[TILE_W * TILE_H / 8 * NBPL];
 
 int game_init(void)
 {
-       int i;
+       REG_COLOR0 = 0x221;
+       REG_COLOR1 = 0x222;
+       REG_COLOR2 = 0x332;
+       REG_COLOR3 = 0x433;
+       REG_COLOR4 = 0x543;
+       REG_COLOR5 = 0x554;
+       REG_COLOR6 = 0x654;
+       REG_COLOR7 = 0x765;
 
-       for(i=0; i<2; i++) {
-               convert_tile_data(test_tiles[i], test_tiles_cpix[i][0]);
-       }
-       convert_tile_data(tile_mask, tile_mask_cpix[0]);
        return 0;
 }
 
+#define XTILES 5
+#define YTILES 13
+
 void game_draw(void)
 {
-       draw_tile(0, 32, 16, 0);
+       int i, j, xoffs, yoffs, ntiles;
+
+       yoffs = 0;
+       for(i=0; i<YTILES; i++) {
+               xoffs = i & 1 ? TILE_W / 2 : 0;
+               ntiles = i & 1 ? XTILES - 1 : XTILES;
+               for(j=0; j<ntiles; j++) {
+                       draw_tile(0, xoffs, yoffs, 0);
+                       xoffs += TILE_W;
+               }
+               yoffs += TILE_H / 2;
+       }
 }
 
 
 void draw_tile(int tid, int x, int y, int light)
 {
        unsigned char *dest = bplptr[0] + (y * SCANSZ * NBPL) + x / 8;
-       unsigned char *src = test_tiles[tid];
+       unsigned char *src = test_tile;
 
        wait_blit();
 
@@ -45,60 +59,9 @@ void draw_tile(int tid, int x, int y, int light)
        REG_BLTBMOD = 0;
        REG_BLTCMOD = SCANSZ - TILE_W / 8;
        REG_BLTDMOD = SCANSZ - TILE_W / 8;
-       REG32_BLTAPT = (intptr_t)tile_mask;
+       REG32_BLTAPT = (intptr_t)test_tile_mask;
        REG32_BLTBPT = (intptr_t)src;
        REG32_BLTCPT = (intptr_t)dest;
        REG32_BLTDPT = (intptr_t)dest;
        REG_BLTSIZE = BLTSIZE(TILE_W, TILE_H * NBPL);
 }
-
-static inline int charpix_color(char c)
-{
-       switch(c) {
-       case '0':
-               return 0;
-       case '#':
-               return 1;
-       case 'x':
-               return 2;
-       case '@':
-               return 3;
-       case 'o':
-               return 4;
-       case '.':
-               return 0x1f;
-       default:
-               break;
-       }
-       return 0;
-}
-
-#define TILE_SCANSZ    (TILE_W / 8)
-void convert_tile_data(unsigned char *dest, const char *src)
-{
-       int i, j, k;
-       unsigned char *bptr[NBPL];
-
-       for(i=0; i<NBPL; i++) {
-               bptr[i] = dest + TILE_SCANSZ * i;
-       }
-
-       for(i=0; i<TILE_H; i++) {
-               for(j=0; j<TILE_W; j++) {
-                       int col = charpix_color(*src++);
-
-                       for(k=0; k<NBPL; k++) {
-                               *bptr[k] = (*bptr[k] << 1) | (col & 1);
-                               col >>= 1;
-
-                               if((j & 7) == 7) {
-                                       bptr[k]++;
-                               }
-                       }
-               }
-
-               for(j=0; j<NBPL; j++) {
-                       bptr[j] += TILE_SCANSZ * (NBPL - 1);
-               }
-       }
-}
diff --git a/tools/conv_gimp b/tools/conv_gimp
new file mode 100755 (executable)
index 0000000..855e5dd
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+if [ -z "$1" ]; then
+       echo "pass the header file exported by gimp as argument"
+       exit 1
+fi
+
+cc -pedantic -Wall -DHDRFILE=\"$1\" -o /tmp/conv_gimp.bin conv_gimp.c
+if [ $? != 0 ]; then
+       exit 1
+fi
+
+/tmp/conv_gimp.bin `basename $1 .h`
diff --git a/tools/conv_gimp.c b/tools/conv_gimp.c
new file mode 100644 (file)
index 0000000..b124d37
--- /dev/null
@@ -0,0 +1,71 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include HDRFILE
+
+#define NBPL   5
+
+int main(int argc, char **argv)
+{
+       int i, j, k, palsz;
+       FILE *fp;
+       char *buf;
+       unsigned char *src;
+
+       if(!argv[1]) {
+               fprintf(stderr, "missing argument: output name\n");
+               return 1;
+       }
+
+       if(!(buf = malloc(strlen(argv[1]) + 4))) {
+               perror("malloc failed");
+               return 1;
+       }
+       sprintf(buf, "%s.img", argv[1]);
+
+       if(!(fp = fopen(buf, "wb"))) {
+               perror("failed to open output file");
+               return 1;
+       }
+
+       src = header_data;
+
+       printf("image: %dx%d\n", width, height);
+       for(i=0; i<height; i++) {
+               for(j=0; j<NBPL; j++) {
+                       int bit = j;
+                       unsigned char out = 0;
+                       for(k=0; k<width; k++) {
+                               out = (out << 1) | ((src[k] >> bit) & 1);
+                               if((k & 7) == 7) {
+                                       fputc(out, fp);
+                               }
+                       }
+               }
+               src += width;
+       }
+       fclose(fp);
+
+       sprintf(buf, "%s.pal", argv[1]);
+       if(!(fp = fopen(buf, "wb"))) {
+               perror("failed to open palette output file");
+               return 1;
+       }
+
+       palsz = 1 << NBPL;
+
+       printf("palette:\n");
+       for(i=0; i<palsz; i++) {
+               int r = header_data_cmap[i][0] >> 4;
+               int g = header_data_cmap[i][1] >> 4;
+               int b = header_data_cmap[i][2] >> 4;
+               unsigned int col = ((r & 0xf) << 8) | ((g & 0xf) << 4) | (b & 0xf);
+               printf("0x%03x\n", col);
+               fputc(col >> 8, fp);
+               fputc(col, fp);
+       }
+       fclose(fp);
+
+       return 0;
+}