nds_test1

view 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 source
1 #include <stdint.h>
2 #include <math.h>
3 #include "dsregs.h"
5 static void xorpat(void *addr, int xsz, int ysz);
7 static void *vram = VRAM_LCDC_PTR;
8 static uint16_t *bgmem = VRAM_BGB_PTR;
10 int main(void)
11 {
12 uint32_t frame;
14 REG_POWCNT1 = POWCNT1_LCD | POWCNT1_2DA | POWCNT1_2DB | POWCNT1_DSWAP;
16 REG_DISPCNT = DISPCNT_MODE(2);
17 REG_B_DISPCNT = DISPCNT_MODE(1) | DISPCNT_BG2 | 5;
19 REG_B_BG2CNT = BGXCNT_BM_256X256 | BGXCNT_BM16 | BGXCNT_OVF_WRAP;
20 REG_B_BG2PA = 0x100;
21 REG_B_BG2PB = 0;
22 REG_B_BG2PC = 0;
23 REG_B_BG2PD = 0x100;
25 REG_VRAMCNT_A = VRAM_ENABLE;
26 REG_VRAMCNT_C = VRAM_ENABLE | 4;
28 xorpat(vram, 256, 192);
29 xorpat(bgmem, 256, 256);
31 for(;;) {
32 float t = (float)frame * 0.00035;
33 float scale = 0.5 * sin(t * 0.8) + 0.8;
34 int32_t sa = (int16_t)(sin(t) * 256 * scale);
35 int32_t ca = (int16_t)(cos(t) * 256 * scale);
37 int32_t x = ca * -128 + sa * -96 + (128 << 8);
38 int32_t y = -sa * -128 + ca * -96 + (96 << 8);
40 while(REG_VCOUNT < 192);
42 REG_B_BG2PA = ca;
43 REG_B_BG2PB = sa;
44 REG_B_BG2PC = -sa;
45 REG_B_BG2PD = ca;
46 REG_B_BG2X = x;
47 REG_B_BG2Y = y;
49 ++frame;
50 }
51 return 0;
52 }
54 static void xorpat(void *addr, int xsz, int ysz)
55 {
56 int i, j;
57 uint16_t *p = addr;
59 for(i=0; i<ysz; i++) {
60 for(j=0; j<xsz; j++) {
61 int xor = i^j;
62 uint16_t red = xor >> 2;
63 uint16_t green = xor >> 1;
64 uint16_t blue = xor;
65 *p++ = 0x8000 | red | ((green & 0x1f) << 5) | ((blue & 0x1f) << 10);
66 }
67 }
68 }