nds_test2
view src/ds3.c @ 0:abcaf667f2bd
initial commit (3d + 2d)
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 28 Jan 2018 20:05:26 +0200 |
parents | |
children | d625ba001a62 |
line source
1 #include <stdint.h>
2 #include "dsregs.h"
3 #include "ds3.h"
5 void ds3_enable(unsigned int x)
6 {
7 REG_DISP3DCNT |= x;
8 }
10 void ds3_disable(unsigned int x)
11 {
12 REG_DISP3DCNT &= ~x;
13 }
15 void ds3_clear_color(uint16_t color, int a)
16 {
17 REG_CLEAR_COLOR = color | ((a & 0x1f) << 16);
18 }
20 void ds3_clear_depth(int z)
21 {
22 REG_CLEAR_DEPTH = z;
23 }
25 void ds3_viewport(int x, int y, int w, int h)
26 {
27 int x1 = x + w - 1;
28 int y1 = y + h - 1;
30 if(x1 > 255) x1 = 255;
31 if(y1 > 191) y1 = 191;
33 REG_VIEWPORT = x | (y << 8) | (x1 << 16) | (y1 << 24);
34 }
36 void ds3_matrix_mode(int mmode)
37 {
38 REG_MTX_MODE = mmode;
39 }
41 void ds3_load_identity(void)
42 {
43 REG_MTX_IDENTITY = 0;
44 }
46 void ds3_load_matrix(int32_t *m)
47 {
48 int i;
49 for(i=0; i<16; i++) {
50 int16_t val = (int16_t)(*m++ >> 4);
51 REG_MTX_LOAD_4X4 = val;
52 }
53 }
55 void ds3_push_matrix(void)
56 {
57 REG_MTX_PUSH = 0;
58 }
60 void ds3_pop_matrix(void)
61 {
62 REG_MTX_POP = 1;
63 }
65 void ds3_translate(int32_t x, int32_t y, int32_t z)
66 {
67 REG_MTX_TRANS = (int16_t)(x >> 4);
68 REG_MTX_TRANS = (int16_t)(y >> 4);
69 REG_MTX_TRANS = (int16_t)(z >> 4);
70 }
72 void ds3_scale(int32_t x, int32_t y, int32_t z)
73 {
74 REG_MTX_SCALE = (int16_t)(x >> 4);
75 REG_MTX_SCALE = (int16_t)(y >> 4);
76 REG_MTX_SCALE = (int16_t)(z >> 4);
77 }
79 void ds3_swap_buffers(void)
80 {
81 REG_SWAP_BUFFERS = 0;
82 }
84 void ds3_begin(int prim)
85 {
86 REG_BEGIN_VTXS = prim;
87 }
89 void ds3_end(void)
90 {
91 REG_END_VTXS = 0;
92 }
94 void ds3_vertex3(int32_t x, int32_t y, int32_t z)
95 {
96 REG_VTX_16 = ((x >> 4) & 0xffff) | ((y << 12) & 0xffff0000);
97 REG_VTX_16 = (z >> 4) & 0xffff;
98 }
100 void ds3_color(uint16_t color)
101 {
102 REG_COLOR = color;
103 }
105 void ds3_color3b(unsigned char r, unsigned char g, unsigned char b)
106 {
107 REG_COLOR = RGB15(r >> 3, g >> 3, b >> 3);
108 }