Browse Source

Implement stack dump function

Implement invert feature for map3d

Fix logical inverse error on checking the ABI version

Revert incorrect fix to vm_spawn_args which worked around the argument
corruption issue in the compiler.
master
Gavan Fantom 17 years ago
parent
commit
d2375baded
  1. 1
      src/lsi/abi.h
  2. 3
      src/lsi/abispec
  3. 23
      src/lsi/map3d.c
  4. 2
      src/lsi/map3d.h
  5. 38
      src/lsi/vm.c

1
src/lsi/abi.h

@ -18,6 +18,7 @@ int vm_intfn___global_store(void);
int vm_intfn___global_load(void);
int vm_intfn___global_array_store(void);
int vm_intfn___global_array_load(void);
int vm_intfn___stackdump(void);
int vm_intfn_printint(void);
int vm_intfn_printreal(void);
int vm_intfn_printstr(void);

3
src/lsi/abispec

@ -7,6 +7,7 @@ function __global_store
function __global_load
function __global_array_store
function __global_array_load
function __stackdump
function printint
function printreal
function printstr
@ -21,7 +22,7 @@ function midi_read
function beatdetect_read
function beatdetect_phase
function beatdetect_confidence
funciton realtoint
function realtoint
function inttoreal
function map3d_setcal
function map3d_calibrate

23
src/lsi/map3d.c

@ -24,6 +24,7 @@ struct light {
double cp[3][3];
double pan[3];
double tilt[3];
int invert;
};
struct light map3d_cal[NLIGHTS];
@ -88,6 +89,10 @@ int map3d_load(void)
return 1;
}
/*
* invert bit 0 = swap x/z
bit 1 = invert pan
*/
void map3d_transform(int light, double x, double y, double z,
int *pan, int *tilt)
{
@ -97,9 +102,15 @@ void map3d_transform(int light, double x, double y, double z,
// printf("Transforming for light %d: (%f, %f, %f)\n", light, x, y, z);
fflush(stdout);
pv[0] = x;
pv[1] = y;
pv[2] = z;
if (map3d_cal[light].invert & 1) {
pv[0] = z;
pv[1] = y;
pv[2] = x;
} else {
pv[0] = x;
pv[1] = y;
pv[2] = z;
}
multiply(light, pv, rv);
normalise(rv);
t = asin(rv[1]);
@ -115,6 +126,8 @@ void map3d_transform(int light, double x, double y, double z,
*tilt = 0;
if (*tilt > 255)
*tilt = 255;
if (map3d_cal[light].invert & 2)
*pan = 255-*pan;
// printf("pan = %d, tilt = %d\n", *pan, *tilt);
}
@ -594,7 +607,7 @@ int map3d_calibrate(int light)
tx, ty = pan, tilt of light fixture
tz = distance from light fixture to (0, 0, 0)
*/
void map3d_setparams(int light, int opan, int otilt, double lpan, double ltilt, double dist)
void map3d_setparams(int light, int opan, int otilt, double lpan, double ltilt, double dist, int invert)
{
double n[3];
double up[3];
@ -636,6 +649,8 @@ void map3d_setparams(int light, int opan, int otilt, double lpan, double ltilt,
map3d_cal[light].M[3][0] = dist*v[0];
map3d_cal[light].M[3][1] = dist*v[1];
map3d_cal[light].M[3][2] = dist*v[2];
printf ("setting invert = %d\n", invert);
map3d_cal[light].invert = invert;
printf("\t%f\t%f\t%f\t\t%f\n", map3d_cal[light].M[0][0], map3d_cal[light].M[0][1], map3d_cal[light].M[0][2], map3d_cal[light].M[3][0]);
printf("\t%f\t%f\t%f\t\t%f\n", map3d_cal[light].M[1][0], map3d_cal[light].M[1][1], map3d_cal[light].M[1][2], map3d_cal[light].M[3][1]);

2
src/lsi/map3d.h

@ -8,4 +8,4 @@ void map3d_save(void);
void map3d_transform(int, double, double, double, int *, int *);
void map3d_setcal(int, int, double, double, double, int, int);
int map3d_calibrate(int);
void map3d_setparams(int, int, int, double, double, double);
void map3d_setparams(int, int, int, double, double, double, int);

38
src/lsi/vm.c

@ -257,6 +257,19 @@ gloadarrayout:
return 1;
}
int vm_intfn___stackdump(void) {
int n = vm_current->sp - vm_current->stackbase;
int i;
printf("\n=====Stack dump======\n");
for (i = 0; i < n; i++) {
int e = stack_get(vm_current, i);
printf("%x\t%d\n", e, e);
}
return 1;
}
int vm_intfn_printint(void)
{
printf("%d", stack_get(vm_current, 1));
@ -768,12 +781,13 @@ int vm_intfn_map3d_transform(void)
int vm_intfn_map3d_setparams(void)
{
map3d_setparams(stack_get(vm_current, 6), /* light */
(double)stack_get(vm_current, 5), /* opan */
(double)stack_get(vm_current, 4), /* otilt */
(double)stack_getreal(vm_current, 3), /* lpan */
(double)stack_getreal(vm_current, 2), /* ltilt */
(double)stack_getreal(vm_current, 1)); /* dist */
map3d_setparams(stack_get(vm_current, 7), /* light */
(double)stack_get(vm_current, 6), /* opan */
(double)stack_get(vm_current, 5), /* otilt */
(double)stack_getreal(vm_current, 4), /* lpan */
(double)stack_getreal(vm_current, 3), /* ltilt */
(double)stack_getreal(vm_current, 2), /* dist */
(double)stack_get(vm_current, 1)); /* invert */
return 1;
}
@ -897,10 +911,10 @@ void vm_init_functions(void)
errx(1, "Bad version - recompile");
if ((GETINT(vm_codearea, 8) != vm_abiversion1) ||
(GETINT(vm_codearea, 12) == vm_abiversion2) ||
(GETINT(vm_codearea, 16) == vm_abiversion3) ||
(GETINT(vm_codearea, 20) == vm_abiversion4) ||
(GETINT(vm_codearea, 24) == vm_abiversion5))
(GETINT(vm_codearea, 12) != vm_abiversion2) ||
(GETINT(vm_codearea, 16) != vm_abiversion3) ||
(GETINT(vm_codearea, 20) != vm_abiversion4) ||
(GETINT(vm_codearea, 24) != vm_abiversion5))
errx(1, "Incompatible ABI version - recompile");
/* Now, get the function table pointer */
@ -992,8 +1006,6 @@ int vm_spawn_args(char *fn, int n, ...)
}
newt->sp = newt->stackbase;
stack_push(newt, 0); /* Return value */
/* Push optional arguments */
va_start(ap, n);
while (n--) {
@ -1003,6 +1015,8 @@ int vm_spawn_args(char *fn, int n, ...)
}
va_end(ap);
stack_push(newt, 0); /* Return value */
/* Push return address here, to point to some special thread exit
routine */
stack_push(newt, 0); /* Return address */

Loading…
Cancel
Save