dquakeplus/source/libpspmath/vfpu_ortho_matrix.c

39 lines
1.7 KiB
C
Raw Normal View History

2022-02-08 21:49:56 +00:00
#include "pspmath.h"
void vfpu_ortho_matrix(ScePspFMatrix4 *m, float left, float right, float bottom, float top, float near, float far) {
__asm__ volatile (
"vmidt.q M100\n" // set M100 to identity
"mtv %2, S000\n" // C000 = [right, ?, ?, ]
"mtv %4, S001\n" // C000 = [right, top, ?, ]
"mtv %6, S002\n" // C000 = [right, top, far ]
"mtv %1, S010\n" // C010 = [left, ?, ?, ]
"mtv %3, S011\n" // C010 = [left, bottom, ?, ]
"mtv %5, S012\n" // C010 = [left, bottom, near]
"vsub.t C020, C000, C010\n" // C020 = [ dx, dy, dz]
"vrcp.t C020, C020\n" // C020 = [1/dx, 1/dy, 1/dz]
"vmul.s S100, S100[2], S020\n" // S100 = m->x.x = 2.0 / dx
"vmul.s S111, S111[2], S021\n" // S110 = m->y.y = 2.0 / dy
"vmul.s S122, S122[2], S022[-x]\n" // S122 = m->z.z = -2.0 / dz
"vsub.t C130, C000[-x,-y,-z], C010\n" // C130 = m->w[x, y, z] = [-(right+left), -(top+bottom), -(far+near)]
// we do vsub here since -(a+b) => (-1*a) + (-1*b) => -a - b
"vmul.t C130, C130, C020\n" // C130 = [-(right+left)/dx, -(top+bottom)/dy, -(far+near)/dz]
"sv.q C100, 0 + %0\n"
"sv.q C110, 16 + %0\n"
"sv.q C120, 32 + %0\n"
"sv.q C130, 48 + %0\n"
:"=m"(*m) : "r"(left), "r"(right), "r"(bottom), "r"(top), "r"(near), "r"(far));
}
void vfpu_transform_vector(ScePspFMatrix4 *m, ScePspFVector4 *vin, ScePspFVector4 *vout) {
__asm__ volatile (
"lv.q C000, 0 + %1\n"
"lv.q C010, 16 + %1\n"
"lv.q C020, 32 + %1\n"
"lv.q C030, 48 + %1\n"
"lv.q C100, %2\n"
"vtfm4.q C110, M000, C100\n"
"sv.q C110, %0\n"
:"+m"(*vout): "m"(*m), "m"(*vin));
}