nds_test1

diff src/main.c @ 0:ab2afb70001a

initial commit test1 without libnds
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 27 Jan 2018 23:38:00 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/main.c	Sat Jan 27 23:38:00 2018 +0200
     1.3 @@ -0,0 +1,68 @@
     1.4 +#include <stdint.h>
     1.5 +#include <math.h>
     1.6 +#include "dsregs.h"
     1.7 +
     1.8 +static void xorpat(void *addr, int xsz, int ysz);
     1.9 +
    1.10 +static void *vram = VRAM_LCDC_PTR;
    1.11 +static uint16_t *bgmem = VRAM_BGB_PTR;
    1.12 +
    1.13 +int main(void)
    1.14 +{
    1.15 +	uint32_t frame;
    1.16 +
    1.17 +	REG_POWCNT1 = POWCNT1_LCD | POWCNT1_2DA | POWCNT1_2DB | POWCNT1_DSWAP;
    1.18 +
    1.19 +	REG_DISPCNT = DISPCNT_MODE(2);
    1.20 +	REG_B_DISPCNT = DISPCNT_MODE(1) | DISPCNT_BG2 | 5;
    1.21 +
    1.22 +	REG_B_BG2CNT = BGXCNT_BM_256X256 | BGXCNT_BM16 | BGXCNT_OVF_WRAP;
    1.23 +	REG_B_BG2PA = 0x100;
    1.24 +	REG_B_BG2PB = 0;
    1.25 +	REG_B_BG2PC = 0;
    1.26 +	REG_B_BG2PD = 0x100;
    1.27 +
    1.28 +	REG_VRAMCNT_A = VRAM_ENABLE;
    1.29 +	REG_VRAMCNT_C = VRAM_ENABLE | 4;
    1.30 +
    1.31 +	xorpat(vram, 256, 192);
    1.32 +	xorpat(bgmem, 256, 256);
    1.33 +
    1.34 +	for(;;) {
    1.35 +		float t = (float)frame * 0.00035;
    1.36 +		float scale = 0.5 * sin(t * 0.8) + 0.8;
    1.37 +		int32_t sa = (int16_t)(sin(t) * 256 * scale);
    1.38 +		int32_t ca = (int16_t)(cos(t) * 256 * scale);
    1.39 +
    1.40 +		int32_t x = ca * -128 + sa * -96 + (128 << 8);
    1.41 +		int32_t y = -sa * -128 + ca * -96 + (96 << 8);
    1.42 +
    1.43 +		while(REG_VCOUNT < 192);
    1.44 +
    1.45 +		REG_B_BG2PA = ca;
    1.46 +		REG_B_BG2PB = sa;
    1.47 +		REG_B_BG2PC = -sa;
    1.48 +		REG_B_BG2PD = ca;
    1.49 +		REG_B_BG2X = x;
    1.50 +		REG_B_BG2Y = y;
    1.51 +
    1.52 +		++frame;
    1.53 +	}
    1.54 +	return 0;
    1.55 +}
    1.56 +
    1.57 +static void xorpat(void *addr, int xsz, int ysz)
    1.58 +{
    1.59 +	int i, j;
    1.60 +	uint16_t *p = addr;
    1.61 +
    1.62 +	for(i=0; i<ysz; i++) {
    1.63 +		for(j=0; j<xsz; j++) {
    1.64 +			int xor = i^j;
    1.65 +			uint16_t red = xor >> 2;
    1.66 +			uint16_t green = xor >> 1;
    1.67 +			uint16_t blue = xor;
    1.68 +			*p++ = 0x8000 | red | ((green & 0x1f) << 5) | ((blue & 0x1f) << 10);
    1.69 +		}
    1.70 +	}
    1.71 +}