add missing tools/pngdump to the repo
[gbajam22] / src / xgl.c
index 3efae76..7d22b2b 100644 (file)
--- a/src/xgl.c
+++ b/src/xgl.c
@@ -20,6 +20,7 @@ along with this program.  If not, see <https://www.gnu.org/licenses/>.
 #include "xgl.h"
 #include "polyfill.h"
 #include "debug.h"
+#include "util.h"
 
 #define MAT_STACK_SIZE 4
 
@@ -29,6 +30,8 @@ static int mtop;
 static unsigned int opt;
 static int32_t ldir[3];
 
+static int cur_cidx;
+
 static void draw_ptlines(int prim, const struct xvertex *varr, int vcount);
 
 
@@ -116,9 +119,13 @@ void xgl_mult_matrix(const int32_t *m2)
        }
 }
 
-/* XXX TODO XXX */
+#if 0
 #define XSIN(x)                (int32_t)(sin(x / 65536.0f) * 65536.0f)
 #define XCOS(x)                (int32_t)(cos(x / 65536.0f) * 65536.0f)
+#else
+#define XSIN(x)                SIN(((x) << 8) / (X_2PI >> 8))
+#define XCOS(x)                COS(((x) << 8) / (X_2PI >> 8))
+#endif
 
 void xgl_translate(int32_t x, int32_t y, int32_t z)
 {
@@ -175,14 +182,19 @@ void xgl_scale(int32_t x, int32_t y, int32_t z)
        xgl_mult_matrix(m);
 }
 
-static void xform(struct xvertex *out, const struct xvertex *in, const int32_t *m)
+void xgl_index(int cidx)
+{
+       cur_cidx = cidx;
+}
+
+static inline void xform(struct xvertex *out, const struct xvertex *in, const int32_t *m)
 {
        out->x = XMUL(m[0], in->x) + XMUL(m[4], in->y) + XMUL(m[8], in->z) + m[12];
        out->y = XMUL(m[1], in->x) + XMUL(m[5], in->y) + XMUL(m[9], in->z) + m[13];
        out->z = XMUL(m[2], in->x) + XMUL(m[6], in->y) + XMUL(m[10], in->z) + m[14];
 }
 
-static void xform_norm(struct xvertex *out, const struct xvertex *in, const int32_t *m)
+static inline void xform_norm(struct xvertex *out, const struct xvertex *in, const int32_t *m)
 {
        out->nx = XMUL(m[0], in->nx) + XMUL(m[4], in->ny) + XMUL(m[8], in->nz);
        out->ny = XMUL(m[1], in->nx) + XMUL(m[5], in->ny) + XMUL(m[9], in->nz);
@@ -194,6 +206,7 @@ static void xform_norm(struct xvertex *out, const struct xvertex *in, const int3
 /* near Z = 0.5 */
 #define NEAR_Z 0x18000
 
+ARM_IWRAM
 void xgl_draw(int prim, const struct xvertex *varr, int vcount)
 {
        int i, cidx, clipnum;
@@ -207,7 +220,7 @@ void xgl_draw(int prim, const struct xvertex *varr, int vcount)
        }
 
        while(vcount >= prim) {
-               cidx = 0xff;//varr->cidx;
+               cidx = cur_cidx;//varr->cidx;
 
                xform(xv, varr, mat[mtop]);
                xform_norm(xv, varr, mat[mtop]);
@@ -305,6 +318,7 @@ void xgl_xyzzy(void)
                (res)->lit = (v0)->lit + (((v1)->lit - (v0)->lit) >> 8) * (t); \
        } while(0)
 
+ARM_IWRAM
 static int clip_edge_near(struct xvertex *poly, int *vnumptr, struct xvertex *v0, struct xvertex *v1)
 {
        int vnum = *vnumptr;
@@ -350,6 +364,7 @@ static int clip_edge_near(struct xvertex *poly, int *vnumptr, struct xvertex *v0
 }
 
 /* special case near-plane clipper */
+ARM_IWRAM
 int xgl_clip_near(struct xvertex *vout, int *voutnum, struct xvertex *vin, int vnum)
 {
        int i, nextidx, res;