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
#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, ...)
#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_ */
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 --- */
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;
}
#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;
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++) {
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;
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++;
}
}
- //while(!(REG_DISPSTAT & DISPSTAT_VBLANK));
- while(REG_VCOUNT < 160);
- //REG_DISPCNT ^= DISPCNT_FB1;
+ vblperf_end();
+ wait_vblank();
present(backbuf);
+ vblperf_start();
}
}
int main(void)
{
- emuprint("\nStarting GBAJAM21\n-----------------\n");
-
intr_init();
#ifndef NOSOUND
--- /dev/null
+#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_ */