blitter test
authorJohn Tsiombikas <nuclear@member.fsf.org>
Wed, 25 Jul 2018 20:14:43 +0000 (23:14 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Wed, 25 Jul 2018 20:14:43 +0000 (23:14 +0300)
src/amiga/gfx.h
src/amiga/hwregs.h
src/amiga/main.c
src/data_test.h
src/game.c

index f3352fd..f2287c1 100644 (file)
 
 #define wait_vblank() wait_vpos(300)
 
+#define wait_blit() \
+       asm volatile ( \
+               "tst 0xdff002\n\t" \
+               "0: btst #6, 0xdff002\n\t" \
+               "bne 0b\n\t")
+
 unsigned char framebuf[BPLSZ * NBPL];
 unsigned char *bplptr[NBPL];
 
index 04385e5..ccedb57 100644 (file)
 #define REG_COPJMP1            REG(REGN_COPJMP1)
 #define REG_COPJMP2            REG(REGN_COPJMP2)
 
+#define REG_BLTCON0            REG(REGN_BLTCON0)
+#define REG_BLTCON1            REG(REGN_BLTCON1)
+#define REG32_BLTCON   *(volatile uint32_t*)(REG_BASE_ADDR | REGN_BLTCON0)
+#define REG_BLTAFWM            REG(REGN_BLTAFWM)
+#define REG_BLTALWM            REG(REGN_BLTALWM)
+#define REG32_BLTAFLWM *(volatile uint32_t*)(REG_BASE_ADDR | REGN_BLTAFWM)
+#define REG_BLTCPTH            REG(REGN_BLTCPTH)
+#define REG_BLTCPTL            REG(REGN_BLTCPTL)
+#define REG32_BLTCPT   *(volatile uint32_t*)(REG_BASE_ADDR | REGN_BLTCPTH)
+#define REG_BLTBPTH            REG(REGN_BLTBPTH)
+#define REG_BLTBPTL            REG(REGN_BLTBPTL)
+#define REG32_BLTBPT   *(volatile uint32_t*)(REG_BASE_ADDR | REGN_BLTBPTH)
+#define REG_BLTAPTH            REG(REGN_BLTAPTH)
+#define REG_BLTAPTL            REG(REGN_BLTAPTL)
+#define REG32_BLTAPT   *(volatile uint32_t*)(REG_BASE_ADDR | REGN_BLTAPTH)
+#define REG_BLTDPTH            REG(REGN_BLTDPTH)
+#define REG_BLTDPTL            REG(REGN_BLTDPTL)
+#define REG32_BLTDPT   *(volatile uint32_t*)(REG_BASE_ADDR | REGN_BLTDPTH)
+#define REG_BLTSIZE            REG(REGN_BLTSIZE)
+#define REG_BLTCMOD            REG(REGN_BLTCMOD)
+#define REG_BLTBMOD            REG(REGN_BLTBMOD)
+#define REG_BLTAMOD            REG(REGN_BLTAMOD)
+#define REG_BLTDMOD            REG(REGN_BLTDMOD)
+#define REG_BLTCDAT            REG(REGN_BLTCDAT)
+#define REG_BLTBDAT            REG(REGN_BLTBDAT)
+#define REG_BLTADAT            REG(REGN_BLTADAT)
+
 #define REG_SERPER             REG(REGN_SERPER)
 #define REG_SERDATR            REG(REGN_SERDATR)
 #define REG_SERDAT             REG(REGN_SERDAT)
@@ -426,6 +453,50 @@ enum {
 
 #define BPLCON0_COUNT(x)       ((x) << 12)
 
+/* blitter control */
+enum {
+       BLTCON0_USED    = 0x0100,
+       BLTCON0_USEC    = 0x0200,
+       BLTCON0_USEB    = 0x0400,
+       BLTCON0_USEA    = 0x0800
+};
+
+enum {
+       BLTCON1_LINE    = 0x0001,
+       BLTCON1_DECR    = 0x0002,
+       BLTCON1_FCI             = 0x0004,
+       BLTCON1_IFE             = 0x0008,
+       BLTCON1_EFE             = 0x0010,
+       BLTCON1_DOFF    = 0x0080
+};
+
+#define BLTCON0_LF(x)  (x)
+#define BLTCON0_ASH(x) ((x) << 12)
+#define BLTCON1_BSH(x) ((x) << 12)
+
+enum {
+       BLTCON_LINE             = 0x00000001,
+       BLTCON_DECR             = 0x00000002,
+       BLTCON_FCI              = 0x00000004,
+       BLTCON_IFE              = 0x00000008,
+       BLTCON_EFE              = 0x00000010,
+       BLTCON_DOFF             = 0x00000080,
+       BLTCON_USED             = 0x01000000,
+       BLTCON_USEC             = 0x02000000,
+       BLTCON_USEB             = 0x04000000,
+       BLTCON_USEA             = 0x08000000
+};
+
+#define BLTCON_LF(x)   ((uint32_t)(x) << 16)
+#define BLTCON_ASH(x)  ((uint32_t)(x) << 28)
+#define BLTCON_BSH(x)  ((uint32_t)(x) << 12)
+
+#define BLTSIZE_XWORDS(x)      ((uint16_t)(x) & 0x7f)
+#define BLTSIZE_X(x)           BLTSIZE_XWORDS((x) / 16)
+#define BLTSIZE_Y(x)           ((uint16_t)(x) << 6)
+#define BLTSIZE(x, y)          (BLTSIZE_X(x) | BLTSIZE_Y(y))
+
+
 #define CIAA_PA_FIR0   0x40
 #define CIAA_PA_FIR1   0x80
 
index 83d86d9..354f1d6 100644 (file)
@@ -34,7 +34,7 @@ int main(void)
        REG32_COP1LC = (uint32_t)coplist;
        REG_COPJMP1 = 0;
 
-       REG_DMACON = SETBITS(DMA_BPL | DMA_COPPER | DMA_MASTER);
+       REG_DMACON = SETBITS(DMA_BPL | DMA_COPPER | DMA_BLITTER | DMA_MASTER);
 
        game_init();
 
index a00cb47..bd5fb9f 100644 (file)
@@ -1,3 +1,22 @@
+const char tile_mask_cpix[16][32] = {
+       "000000000000000..000000000000000",
+       "0000000000000......0000000000000",
+       "00000000000..........00000000000",
+       "000000000..............000000000",
+       "0000000..................0000000",
+       "00000......................00000",
+       "000..........................000",
+       "0..............................0",
+       "0..............................0",
+       "000..........................000",
+       "00000......................00000",
+       "0000000..................0000000",
+       "000000000..............000000000",
+       "00000000000..........00000000000",
+       "0000000000000......0000000000000",
+       "000000000000000..000000000000000"
+};
+
 const char test_tiles_cpix[][16][32] = {
        {
                "...............#x...............",
index b4baeca..a4dc4c7 100644 (file)
@@ -3,6 +3,8 @@
 #include "data_test.h"
 #include "gfx.h"
 
+#include "hwregs.h"    /* XXX */
+
 #define TILE_W 32
 #define TILE_H 16
 
@@ -10,6 +12,7 @@ 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)
 {
@@ -18,6 +21,7 @@ int game_init(void)
        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;
 }
 
@@ -29,21 +33,30 @@ void game_draw(void)
 
 void draw_tile(int tid, int x, int y, int light)
 {
-       int i;
-
        unsigned char *dest = bplptr[0] + (y * SCANSZ * NBPL) + x / 8;
        unsigned char *src = test_tiles[tid];
 
-       for(i=0; i<TILE_H * NBPL; i++) {
-               memcpy(dest, src, TILE_W / 8);
-               dest += SCANSZ;
-               src += TILE_W / 8;
-       }
+       wait_blit();
+
+       REG32_BLTCON = BLTCON_USEA | BLTCON_USEB | BLTCON_USEC | BLTCON_USED |
+               BLTCON_LF(0xca);
+       REG32_BLTAFLWM = 0xffffffff;
+       REG_BLTAMOD = 0;
+       REG_BLTBMOD = 0;
+       REG_BLTCMOD = SCANSZ - TILE_W / 8;
+       REG_BLTDMOD = SCANSZ - TILE_W / 8;
+       REG32_BLTAPT = (intptr_t)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':
@@ -52,8 +65,9 @@ static inline int charpix_color(char c)
                return 3;
        case 'o':
                return 4;
-       default:
        case '.':
+               return 0x1f;
+       default:
                break;
        }
        return 0;