foo
authorJohn Tsiombikas <nuclear@member.fsf.org>
Sat, 10 Apr 2021 09:51:33 +0000 (12:51 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Sat, 10 Apr 2021 09:51:33 +0000 (12:51 +0300)
libs/aas/Makefile
src/debug.c
src/debug.h
src/dma.c
src/gamescr.c
src/main.c
src/util.h [new file with mode: 0644]

index 2c84074..21b4e59 100644 (file)
@@ -6,7 +6,7 @@ CC = $(TCPREFIX)gcc
 AS = $(TCPREFIX)as
 AR = $(TCPREFIX)ar
 
-CFLAGS = -mthumb -O3 -funroll-loops -mcpu=arm7tdmi -ffast-math \
+CFLAGS = -mthumb -O3 -g -funroll-loops -mcpu=arm7tdmi -ffast-math \
                 -fno-exceptions -mthumb-interwork -fomit-frame-pointer
 ASFLAGS = -mthumb-interwork
 
index 14e00c0..d4c2426 100644 (file)
@@ -1,7 +1,35 @@
 #include <stdio.h>
 #include <stdarg.h>
+#include "gbaregs.h"
+#include "intr.h"
 #include "debug.h"
 
+uint16_t vblperf_color[] = {0x3e0, 0xffc0, 0x3ff, 0x1ff, 0x001f, 0xf81f};
+
+static void vblperf_intr(void)
+{
+       vblperf_count++;
+}
+
+void vblperf_start(int palidx)
+{
+       vblperf_palptr = (uint16_t*)CRAM_BG_ADDR + palidx;
+       intr_disable();
+       REG_DISPSTAT |= DISPSTAT_IEN_VBLANK;
+       interrupt(INTR_VBLANK, vblperf_intr);
+       unmask(INTR_VBLANK);
+       intr_enable();
+}
+
+void vblperf_stop(void)
+{
+       intr_disable();
+       REG_DISPSTAT &= ~DISPSTAT_IEN_VBLANK;
+       interrupt(INTR_VBLANK, 0);
+       mask(INTR_VBLANK);
+       intr_enable();
+}
+
 #ifdef EMUBUILD
 __attribute__((target("arm")))
 void emuprint(const char *fmt, ...)
index 41f2a23..ed45802 100644 (file)
@@ -1,6 +1,25 @@
 #ifndef DEBUG_H_
 #define DEBUG_H_
 
+extern uint16_t vblperf_color[];
+uint16_t *vblperf_palptr;
+int vblperf_count;
+
+void vblperf_start(int palidx);
+void vblperf_stop(void);
+
+#define vblperf_begin()        \
+       do { \
+               *vblperf_palptr = 0; \
+               vblperf_count = 0; \
+       } while(0)
+
+#define vblperf_end() \
+       do { \
+               *vblperf_palptr = vblperf_color[vblperf_count]; \
+               vblperf_count = 0; \
+       } while(0)
+
 void emuprint(const char *fmt, ...);
 
 #endif /* DEBUG_H_ */
index 9efade4..5de4faf 100644 (file)
--- a/src/dma.c
+++ b/src/dma.c
@@ -31,24 +31,28 @@ void AAS_DoDMA3(void*, void*, uint32_t);
 
 void dma_copy32(int channel, void *dst, void *src, int words, unsigned int flags)
 {
+#ifndef NOSOUND
        if(channel == 3) {
                AAS_DoDMA3(src, dst, words | flags | DMA_32 | DMA_ENABLE);
-       } else {
-               reg_dma[channel][DMA_SRC] = (uint32_t)src;
-               reg_dma[channel][DMA_DST] = (uint32_t)dst;
-               reg_dma[channel][DMA_CTRL] = words | flags | DMA_32 | DMA_ENABLE;
+               return;
        }
+#endif
+       reg_dma[channel][DMA_SRC] = (uint32_t)src;
+       reg_dma[channel][DMA_DST] = (uint32_t)dst;
+       reg_dma[channel][DMA_CTRL] = words | flags | DMA_32 | DMA_ENABLE;
 }
 
 void dma_copy16(int channel, void *dst, void *src, int halfwords, unsigned int flags)
 {
+#ifndef NOSOUND
        if(channel == 3) {
                AAS_DoDMA3(src, dst, halfwords | flags | DMA_16 | DMA_ENABLE);
-       } else {
-               reg_dma[channel][DMA_SRC] = (uint32_t)src;
-               reg_dma[channel][DMA_DST] = (uint32_t)dst;
-               reg_dma[channel][DMA_CTRL] = halfwords | flags | DMA_16 | DMA_ENABLE;
+               return;
        }
+#endif
+       reg_dma[channel][DMA_SRC] = (uint32_t)src;
+       reg_dma[channel][DMA_DST] = (uint32_t)dst;
+       reg_dma[channel][DMA_CTRL] = halfwords | flags | DMA_16 | DMA_ENABLE;
 }
 
 /* --- fill a buffer with an ammount of words and halfwords using DMA --- */
@@ -58,23 +62,27 @@ static uint32_t fill[4];
 void dma_fill32(int channel, void *dst, uint32_t val, int words)
 {
        fill[channel] = val;
+#ifndef NOSOUND
        if(channel == 3) {
                AAS_DoDMA3(fill + channel, dst, words | DMA_SRC_FIX | DMA_TIMING_IMMED | DMA_32 | DMA_ENABLE);
-       } else {
-               reg_dma[channel][DMA_SRC] = (uint32_t)(fill + channel);
-               reg_dma[channel][DMA_DST] = (uint32_t)dst;
-               reg_dma[channel][DMA_CTRL] = words | DMA_SRC_FIX | DMA_TIMING_IMMED | DMA_32 | DMA_ENABLE;
+               return;
        }
+#endif
+       reg_dma[channel][DMA_SRC] = (uint32_t)(fill + channel);
+       reg_dma[channel][DMA_DST] = (uint32_t)dst;
+       reg_dma[channel][DMA_CTRL] = words | DMA_SRC_FIX | DMA_TIMING_IMMED | DMA_32 | DMA_ENABLE;
 }
 
 void dma_fill16(int channel, void *dst, uint16_t val, int halfwords)
 {
        fill[channel] = val;
+#ifndef NOSOUND
        if(channel == 3) {
                AAS_DoDMA3(fill + channel, dst, halfwords | DMA_SRC_FIX | DMA_TIMING_IMMED | DMA_16 | DMA_ENABLE);
-       } else {
-               reg_dma[channel][DMA_SRC] = (uint32_t)(fill + channel);
-               reg_dma[channel][DMA_DST] = (uint32_t)dst;
-               reg_dma[channel][DMA_CTRL] = halfwords | DMA_SRC_FIX | DMA_TIMING_IMMED | DMA_16 | DMA_ENABLE;
+               return;
        }
+#endif
+       reg_dma[channel][DMA_SRC] = (uint32_t)(fill + channel);
+       reg_dma[channel][DMA_DST] = (uint32_t)dst;
+       reg_dma[channel][DMA_CTRL] = halfwords | DMA_SRC_FIX | DMA_TIMING_IMMED | DMA_16 | DMA_ENABLE;
 }
index 330331e..4c7d6ba 100644 (file)
@@ -2,14 +2,10 @@
 #include "gbaregs.h"
 #include "dma.h"
 #include "data.h"
+#include "util.h"
+#include "intr.h"
 #include "debug.h"
 
-#define present(x) \
-       do { \
-               REG_DISPCNT = DISPCNT_BG2 | 4 | ((x) << 4); \
-       } while(0)
-
-
 void gamescr(void)
 {
        int i, j, tx, ty, angle, depth, nframes, backbuf, zoffs;
@@ -20,6 +16,8 @@ void gamescr(void)
 
        REG_DISPCNT = 4 | DISPCNT_BG2 | DISPCNT_FB1;
 
+       vblperf_start(0xff);
+
        cdst = (uint16_t*)CRAM_BG_ADDR;
        csrc = tuncross_cmap;
        for(i=0; i<256; i++) {
@@ -27,6 +25,9 @@ void gamescr(void)
                csrc += 3;
        }
 
+       dma_fill16(3, vram[0], 0xffff, 240 * 160 / 2);
+       dma_fill16(3, vram[1], 0xffff, 240 * 160 / 2);
+
        nframes = 0;
        for(;;) {
                backbuf = ++nframes & 1;
@@ -36,7 +37,9 @@ void gamescr(void)
                cdst = vram[backbuf];
                tunptr = tunmap;
                for(i=0; i<160; i++) {
-                       for(j=0; j<240/2; j++) {
+                       cdst++;
+                       tunptr += 2;
+                       for(j=1; j<240/2; j++) {
                                uint16_t pp;
 
                                tun = *tunptr++;
@@ -57,9 +60,9 @@ void gamescr(void)
                        }
                }
 
-               //while(!(REG_DISPSTAT & DISPSTAT_VBLANK));
-               while(REG_VCOUNT < 160);
-               //REG_DISPCNT ^= DISPCNT_FB1;
+               vblperf_end();
+               wait_vblank();
                present(backbuf);
+               vblperf_start();
        }
 }
index e358302..8f122b5 100644 (file)
@@ -14,8 +14,6 @@
 
 int main(void)
 {
-       emuprint("\nStarting GBAJAM21\n-----------------\n");
-
        intr_init();
 
 #ifndef NOSOUND
diff --git a/src/util.h b/src/util.h
new file mode 100644 (file)
index 0000000..e5f3784
--- /dev/null
@@ -0,0 +1,22 @@
+#ifndef UTIL_H_
+#define UTIL_H_
+
+#define wait_vblank() \
+       do { \
+               while(REG_DISPSTAT & DISPSTAT_VBLANK); \
+               while(!(REG_DISPSTAT & DISPSTAT_VBLANK)); \
+       } while(0)
+
+#define present(x) \
+       do { \
+               REG_DISPCNT = DISPCNT_BG2 | DISPCNT_OBJ | 4 | ((x) << 4); \
+       } while(0)
+
+
+#define set_bg_color(idx, r, g, b) \
+       do { \
+               ((uint16_t*)CRAM_BG_ADDR)[idx] = (uint16_t)(r) | ((uint16_t)(g) << 5) | ((uint16_t)(b) << 10); \
+       } while(0)
+
+
+#endif /* UTIL_H_ */