nds_test2

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/ds3.c	Sun Jan 28 20:05:26 2018 +0200
     1.3 @@ -0,0 +1,108 @@
     1.4 +#include <stdint.h>
     1.5 +#include "dsregs.h"
     1.6 +#include "ds3.h"
     1.7 +
     1.8 +void ds3_enable(unsigned int x)
     1.9 +{
    1.10 +	REG_DISP3DCNT |= x;
    1.11 +}
    1.12 +
    1.13 +void ds3_disable(unsigned int x)
    1.14 +{
    1.15 +	REG_DISP3DCNT &= ~x;
    1.16 +}
    1.17 +
    1.18 +void ds3_clear_color(uint16_t color, int a)
    1.19 +{
    1.20 +	REG_CLEAR_COLOR = color | ((a & 0x1f) << 16);
    1.21 +}
    1.22 +
    1.23 +void ds3_clear_depth(int z)
    1.24 +{
    1.25 +	REG_CLEAR_DEPTH = z;
    1.26 +}
    1.27 +
    1.28 +void ds3_viewport(int x, int y, int w, int h)
    1.29 +{
    1.30 +	int x1 = x + w - 1;
    1.31 +	int y1 = y + h - 1;
    1.32 +
    1.33 +	if(x1 > 255) x1 = 255;
    1.34 +	if(y1 > 191) y1 = 191;
    1.35 +
    1.36 +	REG_VIEWPORT = x | (y << 8) | (x1 << 16) | (y1 << 24);
    1.37 +}
    1.38 +
    1.39 +void ds3_matrix_mode(int mmode)
    1.40 +{
    1.41 +	REG_MTX_MODE = mmode;
    1.42 +}
    1.43 +
    1.44 +void ds3_load_identity(void)
    1.45 +{
    1.46 +	REG_MTX_IDENTITY = 0;
    1.47 +}
    1.48 +
    1.49 +void ds3_load_matrix(int32_t *m)
    1.50 +{
    1.51 +	int i;
    1.52 +	for(i=0; i<16; i++) {
    1.53 +		int16_t val = (int16_t)(*m++ >> 4);
    1.54 +		REG_MTX_LOAD_4X4 = val;
    1.55 +	}
    1.56 +}
    1.57 +
    1.58 +void ds3_push_matrix(void)
    1.59 +{
    1.60 +	REG_MTX_PUSH = 0;
    1.61 +}
    1.62 +
    1.63 +void ds3_pop_matrix(void)
    1.64 +{
    1.65 +	REG_MTX_POP = 1;
    1.66 +}
    1.67 +
    1.68 +void ds3_translate(int32_t x, int32_t y, int32_t z)
    1.69 +{
    1.70 +	REG_MTX_TRANS = (int16_t)(x >> 4);
    1.71 +	REG_MTX_TRANS = (int16_t)(y >> 4);
    1.72 +	REG_MTX_TRANS = (int16_t)(z >> 4);
    1.73 +}
    1.74 +
    1.75 +void ds3_scale(int32_t x, int32_t y, int32_t z)
    1.76 +{
    1.77 +	REG_MTX_SCALE = (int16_t)(x >> 4);
    1.78 +	REG_MTX_SCALE = (int16_t)(y >> 4);
    1.79 +	REG_MTX_SCALE = (int16_t)(z >> 4);
    1.80 +}
    1.81 +
    1.82 +void ds3_swap_buffers(void)
    1.83 +{
    1.84 +	REG_SWAP_BUFFERS = 0;
    1.85 +}
    1.86 +
    1.87 +void ds3_begin(int prim)
    1.88 +{
    1.89 +	REG_BEGIN_VTXS = prim;
    1.90 +}
    1.91 +
    1.92 +void ds3_end(void)
    1.93 +{
    1.94 +	REG_END_VTXS = 0;
    1.95 +}
    1.96 +
    1.97 +void ds3_vertex3(int32_t x, int32_t y, int32_t z)
    1.98 +{
    1.99 +	REG_VTX_16 = ((x >> 4) & 0xffff) | ((y << 12) & 0xffff0000);
   1.100 +	REG_VTX_16 = (z >> 4) & 0xffff;
   1.101 +}
   1.102 +
   1.103 +void ds3_color(uint16_t color)
   1.104 +{
   1.105 +	REG_COLOR = color;
   1.106 +}
   1.107 +
   1.108 +void ds3_color3b(unsigned char r, unsigned char g, unsigned char b)
   1.109 +{
   1.110 +	REG_COLOR = RGB15(r >> 3, g >> 3, b >> 3);
   1.111 +}