Fix style of md2_2_bin

Run `dos2unix` and `indent -linux` on the files and some other minor
fixes.
This commit is contained in:
Antonio Niño Díaz 2019-05-30 17:38:48 +01:00
parent bd0ce8d9a0
commit 8fe1bfce3c
5 changed files with 526 additions and 453 deletions

2
Tools/Windows/md2_to_bin/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.o
md2_2_bin

View File

@ -1,95 +1,101 @@
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
// //
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz // Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
#include <malloc.h> #include <stdio.h>
#include "dlmaker.h" #include <stdlib.h>
#include "nds.h"
#include "dlmaker.h"
unsigned int DLSize[1024]; #include "nds.h"
unsigned int * DLPointer[1024];
int DLcount = 0; unsigned int DLSize[1024];
unsigned int *DLPointer[1024];
unsigned char command[4]; int DLcount = 0;
int commands;
unsigned char command[4];
unsigned int param[8]; int commands;
int params;
unsigned int param[8];
void NewDL(void) int params;
{
command[0] = command[1] = command[2] = command[3] = 0; void NewDL(void)
param[0] = param[1] = param[2] = param[3] = 0; {
param[4] = param[5] = param[6] = param[7] = 0; command[0] = command[1] = command[2] = command[3] = 0;
commands = 0; params = 0; param[0] = param[1] = param[2] = param[3] = 0;
param[4] = param[5] = param[6] = param[7] = 0;
DLPointer[DLcount] = (unsigned int*)malloc(DEFAULT_DL_SIZE); commands = 0;
DLSize[DLcount] = 1; params = 0;
}
DLPointer[DLcount] = (unsigned int *)malloc(DEFAULT_DL_SIZE);
void NewCommandDL(int id) DLSize[DLcount] = 1;
{ }
command[commands] = id;
commands++; void NewCommandDL(int id)
{
if(commands == 4) //Save data to display list command[commands] = id;
{ commands++;
commands = 0;
unsigned int temp; if (commands == 4) {
temp = COMMAND_PACK(command[0],command[1],command[2],command[3]); // Save data to display list
command[0] = command[1] = command[2] = command[3] = 0; commands = 0;
unsigned int * pointer = &((DLPointer[DLcount])[DLSize[DLcount]]); unsigned int temp;
*pointer = temp; //Save commands temp =
DLSize[DLcount] ++; COMMAND_PACK(command[0], command[1], command[2],
if(param > 0) command[3]);
{ command[0] = command[1] = command[2] = command[3] = 0;
pointer = &((DLPointer[DLcount])[DLSize[DLcount]]); unsigned int *pointer =
int a; &((DLPointer[DLcount])[DLSize[DLcount]]);
for(a = 0; a < params; a ++) // Save commands
{ *pointer = temp;
pointer[a] = param[a]; //Save commands DLSize[DLcount]++;
DLSize[DLcount] ++; if (param > 0) {
} pointer = &((DLPointer[DLcount])[DLSize[DLcount]]);
} int a;
param[0] = param[1] = param[2] = param[3] = 0; for (a = 0; a < params; a++) {
param[4] = param[5] = param[6] = param[7] = 0; // Save commands
params = 0; pointer[a] = param[a];
DLSize[DLcount]++;
if(DLSize[DLcount] >= DEFAULT_DL_SIZE) }
{ }
printf("\n\nDisplay list buffer overflow.\n\n"); param[0] = param[1] = param[2] = param[3] = 0;
while(1); //TODO: Exit in a better way. param[4] = param[5] = param[6] = param[7] = 0;
} params = 0;
}
} if (DLSize[DLcount] >= DEFAULT_DL_SIZE) {
printf("\n\nDisplay list buffer overflow.\n\n");
void NewParamDL(unsigned int param_) // TODO: Exit in a better way.
{ while (1) ;
param[params] = param_; }
params++; }
} }
void FinishDL(void) void NewParamDL(unsigned int param_)
{ {
if(commands > 0) //Add NOP commands to fill packed commands param[params] = param_;
{ params++;
while(1) }
{
NewCommandDL(ID_NOP); void FinishDL(void)
if(commands == 0) break; {
} if (commands > 0) {
} // Add NOP commands to fill packed commands
*DLPointer[DLcount] = DLSize[DLcount] - 1; //DL real size in 4 bytes packs while (1) {
DLcount++; NewCommandDL(ID_NOP);
} if (commands == 0)
break;
int GetDLSize(int num) }
{ }
return DLSize[num]; // DL real size in 4 bytes packs
} *DLPointer[DLcount] = DLSize[DLcount] - 1;
DLcount++;
unsigned int * GetDLPointer(int num) }
{
return DLPointer[num]; int GetDLSize(int num)
} {
return DLSize[num];
}
unsigned int *GetDLPointer(int num)
{
return DLPointer[num];
}

View File

@ -1,18 +1,18 @@
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
// //
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz // Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
#ifndef _DLMAKER_H_ #ifndef DLMAKER_H__
#define _DLMAKER_H_ #define DLMAKER_H__
#define DEFAULT_DL_SIZE (512*1024) #define DEFAULT_DL_SIZE (512 * 1024)
void NewDL(void); void NewDL(void);
void NewCommandDL(int id); void NewCommandDL(int id);
void NewParamDL(unsigned int param_); void NewParamDL(unsigned int param_);
void FinishDL(void); void FinishDL(void);
int GetDLSize(int num); int GetDLSize(int num);
unsigned int * GetDLPointer(int num); unsigned int *GetDLPointer(int num);
#endif #endif // DLMAKER_H__

View File

@ -1,302 +1,365 @@
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
// //
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz // Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// I used the information in this web to make the converter: // I used the information in this web to make the converter:
// http://tfc.duke.free.fr/coding/md2-specs-en.html // http://tfc.duke.free.fr/coding/md2-specs-en.html
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <malloc.h>
#include "nds.h"
#include "nds.h" #include "dlmaker.h"
#include "dlmaker.h"
#define MAX_PATHLEN 1024
#define MAX_PATHLEN 1024
#define absf(x) (((x) > 0) ? (x) : -(x))
#define absf(x) (((x) > 0) ? (x) : -(x))
typedef float vec3_t[3];
typedef float vec3_t[3];
typedef struct {
typedef struct int ident;
{ int version;
int ident; int version;
int skinwidth;
int skinwidth; int skinheight; int skinheight;
int framesize; int framesize;
int num_skins; int num_vertices; int num_st; int num_tris; int num_glcmds; int num_frames; int num_skins;
int offset_skins; int offset_st; int offset_tris; int offset_frames; int offset_glcmds; int num_vertices;
int offset_end; int num_st;
} md2_header_t; int num_tris;
int num_glcmds;
typedef struct { short s; short t; } md2_texCoord_t; int num_frames;
int offset_skins;
typedef struct { unsigned short vertex[3]; unsigned short st[3]; } md2_triangle_t; int offset_st;
int offset_tris;
typedef struct { unsigned char v[3]; unsigned char normalIndex; } md2_vertex_t; int offset_frames;
int offset_glcmds;
typedef struct { int offset_end;
vec3_t scale; vec3_t translate; } md2_header_t;
char name[16];
md2_vertex_t *verts; typedef struct {
} md2_frame_t; short s;
short t;
typedef struct { float s; float t; int index; } md2_glcmd_t; } md2_texCoord_t;
float anorms[162][3] = { typedef struct {
#include "anorms.h" unsigned short vertex[3];
}; unsigned short st[3];
} md2_triangle_t;
void PrintUse(void) typedef struct {
{ unsigned char v[3];
printf("\n\nInstructions:\n\n"); unsigned char normalIndex;
printf(" MD2_2_BIN [input.md2] [output.bin] ([float scale])\n"); } md2_vertex_t;
printf(" ([float translate x] [float translate x] [float translate x])\n\n");
} typedef struct {
vec3_t scale;
int floattovtx10(float n) vec3_t translate;
{ char name[16];
int value = ((v10)((n) * (1 << 6))) & 0x3FF; md2_vertex_t *verts;
if(n < 0) value |= (1 << 10); } md2_frame_t;
else value &= 0x1FF;
return value; typedef struct {
} float s;
float t;
int main(int argc, char* argv[]) int index;
{ } md2_glcmd_t;
printf("\n\n ########################################\n");
printf(" #/ \\#\n"); float anorms[162][3] = {
printf(" # -- -- MD2 2 BIN -- -- #\n"); #include "anorms.h"
printf(" #\\ v2.0 /#\n"); };
printf(" ########################################\n");
void PrintUse(void)
printf("\nCopyright (C) 2008 Antonio Ni%co D%caz\nAll rights reserved.\n\n", 164, 161); {
printf("\n\n");
printf(" -- -- -- -- -- -- -- -- -- --\n"); printf("Instructions:\n");
printf(" md2_2_bin [input.md2] [output.bin] <[float scale]>\n");
float general_scale = 1; //DEFAULT VALUES printf(" <[float translate x] [float translate x] [float translate x]>\n\n");
float general_trans[3] = {0, 0, 0}; }
switch(argc) int floattovtx10(float n)
{ {
case 0: int value = ((v10) ((n) * (1 << 6))) & 0x3FF;
case 1: if (n < 0)
case 2: //Not enough value |= (1 << 10);
PrintUse(); else
return -1; value &= 0x1FF;
case 3: //Use default modifications return value;
break; }
case 4: //Use default translation and custom scale
general_scale = atof(argv[3]); int IsValidSize(int size)
break; {
case 5: return (size == 8 || size == 16 || size == 32 || size == 64 ||
case 6: //Custom translation, not enough size == 128 || size == 256 || size == 512 || size == 1024);
printf("You must set 3 coordinates for translation, not less."); }
PrintUse();
return -1; int main(int argc, char *argv[])
case 7: //Custom translation + scale {
general_scale = atof(argv[3]); printf("\n\n");
general_trans[0] = atof(argv[4]); printf(" ########################################\n");
general_trans[1] = atof(argv[5]); printf(" # #\n");
general_trans[2] = atof(argv[6]); printf(" # -- -- MD2 2 BIN -- -- #\n");
break; printf(" # v2.0 #\n");
default: //The rest... printf(" ########################################\n");
PrintUse(); printf("\n");
return -1; printf("Copyright (c) 2008-2011, 2019 Antonio Nino Diaz\n");
} printf("All rights reserved.\n\n");
char inputfilepath[MAX_PATHLEN]; // Default values
char outputfilepath[MAX_PATHLEN]; float global_scale = 1;
float global_translation[3] = { 0, 0, 0 };
strcpy(inputfilepath,argv[1]);
strcpy(outputfilepath,argv[2]); switch (argc) {
case 0:
if(general_scale == 0) case 1:
{ case 2:
printf("\nScale can't be 0!!"); // Not enough arguments
PrintUse(); PrintUse();
return -1; return -1;
} case 3:
// Use default modifications
char * md2data; break;
case 4:
printf("\nScale: %f\n",general_scale); // Use default translation and custom scale
printf("Translate: %f, %f, %f\n",general_trans[0],general_trans[1],general_trans[2]); global_scale = atof(argv[3]);
break;
printf("\nLoading MD2 model...\n"); case 5:
case 6:
FILE * datafile = fopen (inputfilepath, "r"); // Custom translation, not enough
if(datafile != NULL) printf("You must set 3 coordinates for translation, not less.");
{ PrintUse();
fseek (datafile , 0 , SEEK_END); return -1;
long int tamano = ftell (datafile); case 7:
rewind (datafile); // Custom translation + scale
md2data = (char*) malloc (sizeof(char)*tamano); global_scale = atof(argv[3]);
fread (md2data,1,tamano,datafile); global_translation[0] = atof(argv[4]);
fclose (datafile); global_translation[1] = atof(argv[5]);
} global_translation[2] = atof(argv[6]);
else break;
{ fclose (datafile); printf("\n\nCouldn't open %s!!\n\n", inputfilepath); default:
PrintUse(); return -1; } // Too many arguments
PrintUse();
md2_header_t * header = (md2_header_t*)md2data; return -1;
}
if ((header->ident != 844121161) || (header->version != 8))
{ printf("\n\nWrong file type or version!!\n\n"); return -1; } char inputfilepath[MAX_PATHLEN];
char outputfilepath[MAX_PATHLEN];
int t_w = header->skinwidth, t_h = header->skinheight; strcpy(inputfilepath, argv[1]);
strcpy(outputfilepath, argv[2]);
if(t_w > 1024 || t_h > 1024) { printf("\n\nTexture too big!!\n\n"); return -1; }
if (global_scale == 0) {
if(!(t_w==8||t_w==16||t_w==32||t_w==64||t_w==128||t_w==256||t_w==512||t_w==1024) || printf("\nScale can't be 0!!");
!(t_h==8||t_h==16||t_h==32||t_h==64||t_h==128||t_h==256||t_h==512||t_h==1024)) PrintUse();
{ return -1;
printf("\nWrong texture size. Must be power of 2.\n"); }
printf("\nAlthough the model uses an invalid texture size, it will be converted.\n");
printf("\nResize the texture to nearest valid size.\n\n"); char *md2data;
//return -1;
} printf("\n");
printf("Scale: %f\n", global_scale);
while(1) printf("Translate: %f, %f, %f\n", global_translation[0],
{ if(t_w==8||t_w==16||t_w==32||t_w==64||t_w==128||t_w==256||t_w==512||t_w==1024) break; global_translation[1], global_translation[2]);
t_w ++; }
while(1) printf("\n");
{ if(t_h==8||t_h==16||t_h==32||t_h==64||t_h==128||t_h==256||t_h==512||t_h==1024) break; printf("Loading MD2 model...\n");
t_h ++; }
FILE *datafile = fopen(inputfilepath, "r");
int num_tris = header->num_tris; if (datafile != NULL) {
fseek(datafile, 0, SEEK_END);
md2_frame_t * frame = NULL; long int size_ = ftell(datafile);
md2_texCoord_t * texcoord = (md2_texCoord_t*)((uintptr_t)header->offset_st + (uintptr_t)header); rewind(datafile);
md2_triangle_t * triangle = (md2_triangle_t*)((uintptr_t)header->offset_tris + (uintptr_t)header); md2data = (char *)malloc(sizeof(char) * size_);
fread(md2data, 1, size_, datafile);
md2_vertex_t * vtx; //Current vertex fclose(datafile);
} else {
printf("\nMD2 texture size: %dx%d", t_w,t_h); fclose(datafile);
printf("\n\nCouldn't open %s!!\n\n", inputfilepath);
printf("\nCreating display list...\n"); PrintUse();
return -1;
float bigvalue = 0; }
//Everything ready, let's "draw" the display list md2_header_t *header = (md2_header_t *) md2data;
frame = (md2_frame_t*)((uintptr_t)header->offset_frames + (uintptr_t)header);
if ((header->ident != 844121161) || (header->version != 8)) {
NewDL(); printf("\n\nWrong file type or version!!\n\n");
NewParamDL(0); // 0 = GL_TRIANGLES return -1;
NewCommandDL(ID_BEGIN); }
int olds_ = -1, oldt_ = -1; //Used to avoid useless command repeating int t_w = header->skinwidth, t_h = header->skinheight;
int oldnormindex = -1;
if (t_w > 1024 || t_h > 1024) {
int vtxcount = 0; printf("\n\nTexture too big!!\n\n");
return -1;
int t = 0, v = 0; }
for(t = 0; t < num_tris; t ++) for(v = 0; v < 3; v++)
{ if (!IsValidSize(t_w) || !IsValidSize(t_h)) {
vtx = (md2_vertex_t*) ( (uintptr_t) (&(frame->verts)) ); printf("\nWrong texture size. It must be a power of 2.\n");
vtx = &vtx[triangle[t].vertex[v]]; printf("\nAlthough the model uses an invalid texture size, it will be converted.\n");
printf("\nResize the texture to nearest valid size.\n\n");
//Texture }
short s_ = texcoord[triangle[t].st[v]].s;
short t_ = texcoord[triangle[t].st[v]].t; while (!IsValidSize(t_w)) {
if(olds_ != s_ || oldt_ != t_) t_w++;
{ }
olds_ = s_; while (!IsValidSize(t_h)) {
oldt_ = t_; t_h++;
}
//This is used to change UVs if using a texture size unsupported by DS
s_ = (int)((float)(s_ * t_w) / (float)header->skinwidth); int num_tris = header->num_tris;
t_ = (int)((float)(t_ * t_h) / (float)header->skinheight);
NewParamDL(TEXTURE_PACK(s_<<4,t_<<4)); // (t_h-t_)<<4)); md2_frame_t *frame = NULL;
NewCommandDL(ID_TEX_COORD); md2_texCoord_t *texcoord =
} (md2_texCoord_t *) ((uintptr_t) header->offset_st +
(uintptr_t) header);
//Normal md2_triangle_t *triangle =
float norm[3]; (md2_triangle_t *) ((uintptr_t) header->offset_tris +
if(oldnormindex != vtx->normalIndex) (uintptr_t) header);
{
oldnormindex = vtx->normalIndex; // Current vertex
int b; md2_vertex_t *vtx;
for(b = 0; b < 3; b++) norm[b] = anorms[vtx->normalIndex][b];
NewParamDL(NORMAL_PACK(floattov10(norm[0]), floattov10(norm[1]), floattov10(norm[2]))); printf("\nMD2 texture size: %dx%d", t_w, t_h);
NewCommandDL(ID_NORMAL);
} printf("\nCreating display list...\n");
//Vertex
float _v[3]; float bigvalue = 0;
int a = 0;
int vtx10 = false; // Everything ready, let's "draw" the display list
for(a = 0; a < 3; a++) frame =
{ (md2_frame_t *) ((uintptr_t) header->offset_frames +
vtxcount ++; (uintptr_t) header);
_v[a] = ((float)frame->scale[a] * (float)(vtx->v[a])) + (float)frame->translate[a];
_v[a] += general_trans[a]; NewDL();
_v[a] *= general_scale;
//7.9997 for VTX_16, 7.98 for VTX_10 // Send GL_TRIANGLES command
if((absf(_v[a]) > (float)7.9997) && ( absf(bigvalue) < absf(_v[a]))) NewParamDL(0);
bigvalue = _v[a]; NewCommandDL(ID_BEGIN);
//Test if OK to use VTX_10
if(absf(_v[a]) < (float)7.98) // Keep track of the last command to avoid useless repetition
{ int olds_ = -1, oldt_ = -1;
float aux = (float)1 / (float)64; int oldnormindex = -1;
float tempvtx = _v[a] / aux;
tempvtx = absf(tempvtx - (float)(int)tempvtx); int vtxcount = 0;
aux = (float)0.2; //You can try changing it, but 0.2 is OK
if(tempvtx < aux || tempvtx > ((float)1 - aux)) vtx10 = true; int t = 0, v = 0;
} for (t = 0; t < num_tris; t++)
} for (v = 0; v < 3; v++) {
if(vtx10) vtx = (md2_vertex_t *) ((uintptr_t) (&(frame->verts)));
{ vtx = &vtx[triangle[t].vertex[v]];
NewParamDL(VERTEX_10_PACK(floattovtx10(_v[0]),floattovtx10(_v[2]),
floattovtx10(_v[1]))); // Texture coordinates
NewCommandDL(ID_VERTEX10); short s_ = texcoord[triangle[t].st[v]].s;
} short t_ = texcoord[triangle[t].st[v]].t;
else if (olds_ != s_ || oldt_ != t_) {
{ olds_ = s_;
NewParamDL((floattov16(_v[2]) << 16) | (floattov16(_v[0]) & 0xFFFF)); oldt_ = t_;
NewParamDL((floattov16(_v[1]) & 0xFFFF));
NewCommandDL(ID_VERTEX16); // This is used to scale UVs if using a texture
} // size unsupported by DS
} s_ = (int)((float)(s_ * t_w) /
FinishDL(); (float)header->skinwidth);
t_ = (int)((float)(t_ * t_h) /
if(absf(bigvalue) > 0) (float)header->skinheight);
{ NewParamDL(TEXTURE_PACK(s_ << 4, t_ << 4)); // (t_h-t_)<<4));
printf("\nModel too big for DS! Scale it down.\n"); NewCommandDL(ID_TEX_COORD);
printf("\nDS max. allowed value: +/-7,9997\nModel max. detected value: %f\n\n",bigvalue); }
return -1; // Normal
} float norm[3];
if (oldnormindex != vtx->normalIndex) {
if(vtxcount > 6144) oldnormindex = vtx->normalIndex;
{ int b;
printf("\nModel has too many vertices!\n"); for (b = 0; b < 3; b++)
printf("\nDS can only render 6144 vertices per frame.\nYour model has %d vertices.\n",vtxcount); norm[b] = anorms[vtx->normalIndex][b];
//return -1; NewParamDL(NORMAL_PACK
} (floattov10(norm[0]),
floattov10(norm[1]),
printf("\nCreating BIN file...\n"); floattov10(norm[2])));
NewCommandDL(ID_NORMAL);
//Now, let's save them into a BIN file. }
FILE * file = fopen(outputfilepath,"wb+"); // Vertex
if(file == NULL) float _v[3];
{ int a = 0;
printf("\nCouldn't create %s file!",outputfilepath); int vtx10 = false;
return -1; for (a = 0; a < 3; a++) {
} vtxcount++;
fwrite((int*)GetDLPointer(0),GetDLSize(0) * sizeof(unsigned int),1,file); _v[a] =
fclose(file); ((float)frame->scale[a] *
(float)(vtx->v[a])) +
FILE * test = fopen(outputfilepath,"rb"); (float)frame->translate[a];
fseek (test , 0 , SEEK_END); _v[a] += global_translation[a];
long int size = ftell (test); _v[a] *= global_scale;
fclose(test); // 7.9997 for VTX_16, 7.98 for VTX_10
printf("\nBIN file size: %zd bytes", size); if ((absf(_v[a]) > (float)7.9997)
&& (absf(bigvalue) < absf(_v[a])))
printf("\n\nReady!\n\n"); bigvalue = _v[a];
// Test to see if it is more accurate to use
return 0; // VTX_10 or VTX_16
} if (absf(_v[a]) < (float)7.98) {
float aux = (float)1 / (float)64;
float tempvtx = _v[a] / aux;
tempvtx =
absf(tempvtx - (float)(int)tempvtx);
// Arbitrary threshold
aux = (float)0.2;
if (tempvtx < aux
|| tempvtx > ((float)1 - aux))
vtx10 = true;
}
}
if (vtx10) {
NewParamDL(VERTEX_10_PACK
(floattovtx10(_v[0]),
floattovtx10(_v[2]),
floattovtx10(_v[1])));
NewCommandDL(ID_VERTEX10);
} else {
NewParamDL((floattov16(_v[2]) << 16) |
(floattov16(_v[0]) & 0xFFFF));
NewParamDL((floattov16(_v[1]) & 0xFFFF));
NewCommandDL(ID_VERTEX16);
}
}
FinishDL();
if (absf(bigvalue) > 0) {
printf("\nModel too big for DS! Scale it down.\n");
printf
("\nDS max. allowed value: +/-7,9997\nModel max. detected value: %f\n\n",
bigvalue);
return -1;
}
if (vtxcount > 6144) {
printf("\nModel has too many vertices!\n");
printf
("\nDS can only render 6144 vertices per frame.\nYour model has %d vertices.\n",
vtxcount);
}
printf("\nCreating BIN file...\n");
// Now, let's save them into a BIN file.
FILE *file = fopen(outputfilepath, "wb+");
if (file == NULL) {
printf("\nCouldn't create %s file!", outputfilepath);
return -1;
}
fwrite((int *)GetDLPointer(0), GetDLSize(0) * sizeof(unsigned int), 1,
file);
fclose(file);
FILE *test = fopen(outputfilepath, "rb");
fseek(test, 0, SEEK_END);
long int size = ftell(test);
fclose(test);
printf("\nBIN file size: %zd bytes\n", size);
printf("\nReady!\n\n");
return 0;
}

View File

@ -1,38 +1,40 @@
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
// //
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz // Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
#ifndef _NDS_H_ #ifndef NDS_H__
#define _NDS_H_ #define NDS_H__
//From libnds/gbatek //From libnds/gbatek
typedef short int v16; typedef short int v16;
typedef short int v10; typedef short int v10;
typedef short int vtx10; typedef short int vtx10;
#define floattov16(n) ((v16)((n) * (1 << 12))) #define floattov16(n) ((v16)((n) * (1 << 12)))
static inline short int floattov10(float n) static inline short int floattov10(float n)
{ {
if(n > 0.998) return 0x1FF; if (n > 0.998)
if(n < -0.998) return 0x3FF; return 0x1FF;
return (short int)(n*(1<<9)); if (n < -0.998)
} return 0x3FF;
return (short int)(n * (1 << 9));
#define floattof32(n) ((int)((n) * (1 << 12))) }
#define VERTEX_10_PACK(x,y,z) (((x) & 0x3FF) | (((y) & 0x3FF) << 10) | (((z) & 0x3FF) << 20)) #define floattof32(n) ((int)((n) * (1 << 12)))
#define NORMAL_PACK(x,y,z) (((x) & 0x3FF) | (((y) & 0x3FF) << 10) | ((z) << 20))
#define TEXTURE_PACK(u,v) (((u) & 0xFFFF) | ((v) << 16)) #define VERTEX_10_PACK(x,y,z) (((x) & 0x3FF) | (((y) & 0x3FF) << 10) | (((z) & 0x3FF) << 20))
#define NORMAL_PACK(x,y,z) (((x) & 0x3FF) | (((y) & 0x3FF) << 10) | ((z) << 20))
#define COMMAND_PACK(c1,c2,c3,c4) (((c4) << 24) | ((c3) << 16) | ((c2) << 8) | (c1)) #define TEXTURE_PACK(u,v) (((u) & 0xFFFF) | ((v) << 16))
#define ID_NOP 0x00 #define COMMAND_PACK(c1, c2, c3, c4) (((c4) << 24) | ((c3) << 16) | ((c2) << 8) | (c1))
#define ID_VERTEX16 0x23
#define ID_VERTEX10 0x24 #define ID_NOP 0x00
#define ID_TEX_COORD 0x22 #define ID_VERTEX16 0x23
#define ID_NORMAL 0x21 #define ID_VERTEX10 0x24
#define ID_BEGIN 0x40 #define ID_TEX_COORD 0x22
#define ID_NORMAL 0x21
#endif #define ID_BEGIN 0x40
#endif // NDS_H__