nds_test2

annotate 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
rev   line source
nuclear@0 1 #include <stdint.h>
nuclear@0 2 #include "dsregs.h"
nuclear@0 3 #include "ds3.h"
nuclear@0 4
nuclear@0 5 void ds3_enable(unsigned int x)
nuclear@0 6 {
nuclear@0 7 REG_DISP3DCNT |= x;
nuclear@0 8 }
nuclear@0 9
nuclear@0 10 void ds3_disable(unsigned int x)
nuclear@0 11 {
nuclear@0 12 REG_DISP3DCNT &= ~x;
nuclear@0 13 }
nuclear@0 14
nuclear@0 15 void ds3_clear_color(uint16_t color, int a)
nuclear@0 16 {
nuclear@0 17 REG_CLEAR_COLOR = color | ((a & 0x1f) << 16);
nuclear@0 18 }
nuclear@0 19
nuclear@0 20 void ds3_clear_depth(int z)
nuclear@0 21 {
nuclear@0 22 REG_CLEAR_DEPTH = z;
nuclear@0 23 }
nuclear@0 24
nuclear@0 25 void ds3_viewport(int x, int y, int w, int h)
nuclear@0 26 {
nuclear@0 27 int x1 = x + w - 1;
nuclear@0 28 int y1 = y + h - 1;
nuclear@0 29
nuclear@0 30 if(x1 > 255) x1 = 255;
nuclear@0 31 if(y1 > 191) y1 = 191;
nuclear@0 32
nuclear@0 33 REG_VIEWPORT = x | (y << 8) | (x1 << 16) | (y1 << 24);
nuclear@0 34 }
nuclear@0 35
nuclear@0 36 void ds3_matrix_mode(int mmode)
nuclear@0 37 {
nuclear@0 38 REG_MTX_MODE = mmode;
nuclear@0 39 }
nuclear@0 40
nuclear@0 41 void ds3_load_identity(void)
nuclear@0 42 {
nuclear@0 43 REG_MTX_IDENTITY = 0;
nuclear@0 44 }
nuclear@0 45
nuclear@0 46 void ds3_load_matrix(int32_t *m)
nuclear@0 47 {
nuclear@0 48 int i;
nuclear@0 49 for(i=0; i<16; i++) {
nuclear@0 50 int16_t val = (int16_t)(*m++ >> 4);
nuclear@0 51 REG_MTX_LOAD_4X4 = val;
nuclear@0 52 }
nuclear@0 53 }
nuclear@0 54
nuclear@0 55 void ds3_push_matrix(void)
nuclear@0 56 {
nuclear@0 57 REG_MTX_PUSH = 0;
nuclear@0 58 }
nuclear@0 59
nuclear@0 60 void ds3_pop_matrix(void)
nuclear@0 61 {
nuclear@0 62 REG_MTX_POP = 1;
nuclear@0 63 }
nuclear@0 64
nuclear@0 65 void ds3_translate(int32_t x, int32_t y, int32_t z)
nuclear@0 66 {
nuclear@0 67 REG_MTX_TRANS = (int16_t)(x >> 4);
nuclear@0 68 REG_MTX_TRANS = (int16_t)(y >> 4);
nuclear@0 69 REG_MTX_TRANS = (int16_t)(z >> 4);
nuclear@0 70 }
nuclear@0 71
nuclear@0 72 void ds3_scale(int32_t x, int32_t y, int32_t z)
nuclear@0 73 {
nuclear@0 74 REG_MTX_SCALE = (int16_t)(x >> 4);
nuclear@0 75 REG_MTX_SCALE = (int16_t)(y >> 4);
nuclear@0 76 REG_MTX_SCALE = (int16_t)(z >> 4);
nuclear@0 77 }
nuclear@0 78
nuclear@0 79 void ds3_swap_buffers(void)
nuclear@0 80 {
nuclear@0 81 REG_SWAP_BUFFERS = 0;
nuclear@0 82 }
nuclear@0 83
nuclear@0 84 void ds3_begin(int prim)
nuclear@0 85 {
nuclear@0 86 REG_BEGIN_VTXS = prim;
nuclear@0 87 }
nuclear@0 88
nuclear@0 89 void ds3_end(void)
nuclear@0 90 {
nuclear@0 91 REG_END_VTXS = 0;
nuclear@0 92 }
nuclear@0 93
nuclear@0 94 void ds3_vertex3(int32_t x, int32_t y, int32_t z)
nuclear@0 95 {
nuclear@0 96 REG_VTX_16 = ((x >> 4) & 0xffff) | ((y << 12) & 0xffff0000);
nuclear@0 97 REG_VTX_16 = (z >> 4) & 0xffff;
nuclear@0 98 }
nuclear@0 99
nuclear@0 100 void ds3_color(uint16_t color)
nuclear@0 101 {
nuclear@0 102 REG_COLOR = color;
nuclear@0 103 }
nuclear@0 104
nuclear@0 105 void ds3_color3b(unsigned char r, unsigned char g, unsigned char b)
nuclear@0 106 {
nuclear@0 107 REG_COLOR = RGB15(r >> 3, g >> 3, b >> 3);
nuclear@0 108 }