Traveler: Add another trivial plane management tool

This commit is contained in:
Gregory Nutt 2014-12-15 07:57:16 -06:00
parent 37816021cb
commit ed7cca7d16
5 changed files with 208 additions and 6 deletions

View File

@ -1,3 +1,6 @@
/pll2txt
/txt2pll
/mktrig
/trigtbl.tmp
/*.exe
/*.dSYM

View File

@ -73,16 +73,19 @@ PLL2TXT_OBJS = $(PLL2TXT_SRCS:.c=$(OBJEXT))
TXT2PLL_SRCS = txt2pll.c
TXT2PLL_OBJS = $(TXT2PLL_SRCS:.c=$(OBJEXT))
OBJS = $(PLL2TXT_OBJS) $(TXT2PLL_OBJS)
MKTRIG_SRCS = mktrig.c
MKTRIG_OBJS = $(MKTRIG_SRCS:.c=$(OBJEXT))
OBJS = $(PLL2TXT_OBJS) $(TXT2PLL_OBJS) $(MKTRIG_OBJS)
# Targets
all: pll2txt$(HOSTEXEEXT) txt2pll$(HOSTEXEEXT)
all: pll2txt$(HOSTEXEEXT) txt2pll$(HOSTEXEEXT) mktrig$(HOSTEXEEXT)
default: all
ifdef HOSTEXEEXT
.PHONY: pll2txt txt2pll clean
.PHONY: pll2txt txt2pll mktrig clean
else
.PHONY: clean
endif
@ -108,9 +111,19 @@ ifdef HOSTEXEEXT
txt2pll: txt2pll$(HOSTEXEEXT)
endif
# mktrig - Regenerate trigonometry look-up tables
mktrig$(HOSTEXEEXT): $(MKTRIG_OBJS)
$(Q) $(HOSTCC) $(HOSTCFLAGS) $< -o $@
ifdef HOSTEXEEXT
mktrig: mktrig$(HOSTEXEEXT)
endif
clean:
$(call DELFILE, pll2txt$(HOSTEXEEXT))
$(call DELFILE, txt2pll$(HOSTEXEEXT))
$(call DELFILE, mktrig$(HOSTEXEEXT))
ifneq ($(CONFIG_WINDOWS_NATIVE),y)
$(Q) rm -rf *.dSYM
endif

View File

@ -0,0 +1,188 @@
/*******************************************************************************
* apps/graphics/traveler/tools/misc/mktrig.c
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included files
****************************************************************************/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/****************************************************************************
* Included files
****************************************************************************/
#define PI 3.1415926
/****************************************************************************
* Included files
****************************************************************************/
int main(int argc, char **argv, char **envp)
{
FILE *outfile;
double angle;
double valuef;
uint32_t value32;
uint16_t value16;
int i;
int j;
outfile = fopen("trigtbl.tmp", "w");
if (!outfile)
{
fprintf(stderr, "Unable to open trigtbl.tmp\n");
exit(1);
}
fprintf(outfile, "#define TWOPI 1920\n");
fprintf(outfile, "#define PI 960\n");
fprintf(outfile, "#define HALFPI 480\n");
fprintf(outfile, "#define QTRPI 240\n\n");
fprintf(outfile, "const int32_t g_tan_table[PI + HALFPI + 1] =\n");
fprintf(outfile, "{\n");
for (i = 0; i < 1440;)
{
fprintf(outfile, " ");
for (j = 0; ((j < 5) && (i < 1440));)
{
angle = ((double)i) * (2.0 * PI / 1920.0);
valuef = (4096.0 * tan(angle));
if (valuef >= 0.0)
{
valuef += 0.5;
}
else
{
valuef -= 0.5;
}
value32 = (uint32_t)((long)(valuef));
fprintf(outfile, "0x%08lx", (unsigned long)value32);
i++;
j++;
if ((j < 5) && (i < 1440))
{
fprintf(outfile, ", ");
}
}
fprintf(outfile, ",\n");
}
fprintf(outfile, " 0x00000000\n");
fprintf(outfile, "};\n\n");
fprintf(outfile, "const int16_t g_sin_table[TWOPI + HALFPI + 1] =\n");
fprintf(outfile, "{\n");
for (i = 0; i < 2400;)
{
fprintf(outfile, " ");
for (j = 0; ((j < 8) && (i < 2400));)
{
angle = ((double)i) * (2.0 * PI / 1920.0);
valuef = (4096.0 * sin(angle));
if (valuef >= 0.0)
{
valuef += 0.5;
}
else
{
valuef -= 0.5;
}
value16 = (uint16_t)((long)(valuef));
fprintf(outfile, "0x%04x", (unsigned int)value16);
i++;
j++;
if ((j < 8) && (i < 2400))
{
fprintf(outfile, ", ");
}
}
fprintf(outfile, ",\n");
}
fprintf(outfile, " 0x1000\n");
fprintf(outfile, "};\n\n");
fprintf(outfile, "const int32_t cscTable[TWOPI + HALFPI + 1] =\n");
fprintf(outfile, "{\n");
for (i = 0; i < 2400;)
{
fprintf(outfile, " ");
for (j = 0; ((j < 5) && (i < 2400));)
{
angle = ((double)i) * (2.0 * PI / 1920.0);
valuef = (4096.0 / sin(angle));
if (valuef >= 0.0)
{
valuef += 0.5;
}
else
{
valuef -= 0.5;
}
value32 = (uint32_t)((long)(valuef));
fprintf(outfile, "0x%08lx", (unsigned long)value32);
i++;
j++;
if ((j < 5) && (i < 2400))
{
fprintf(outfile, ", ");
}
}
fprintf(outfile, ",\n");
}
fprintf(outfile, " 0x00001000\n");
fprintf(outfile, "};\n\n");
fclose(outfile);
return 0;
}

View File

@ -1,6 +1,5 @@
/*******************************************************************************
* apps/graphics/traveler/tools/misc/pll2txt.c
* This file contains low-level texture bitmap logic
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>

View File

@ -1,6 +1,5 @@
/*******************************************************************************
* apps/graphics/traveler/tools/misc/pll2txt.c
* This file contains low-level texture bitmap logic
* apps/graphics/traveler/tools/misc/txt2pll.c
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>