spintcl.c 6.95 KB
#include <sys/types.h>
#include <sys/ipc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <tcl.h>

#include "os.h"
#include <PR/mbi.h>
#include "sys/u64gio.h" 
#include <ultrahost.h>

#include "spin.h"
#include "spincontrol.h"

static int u64fd;

int SpinTclProj(ClientData data, Tcl_Interp *interp, int argc, char *argv[])
{
    int i,fov,near,far;
    float aspect;
    SpinControl sp;

    fov = atoi(argv[0]);
    aspect = atof(argv[1]);
    near = atoi(argv[2]);
    far = atoi(argv[3]);

    sp.type = SPIN_PROJ_TYPE;
    sp.u_msg.proj.fov = fov;
    sp.u_msg.proj.aspect = aspect;
    sp.u_msg.proj.near = near;
    sp.u_msg.proj.far = far;

    uhWriteGame(u64fd, &sp, sizeof(SpinControl));

    strcpy(interp->result, "SpinTclMouse passed");
    return TCL_OK;
}

int SpinTclMouse(ClientData data, Tcl_Interp *interp, int argc, char *argv[])
{
    int i,mouseX, mouseY;
    int buttons;
    SpinControl sp;

    mouseX = atoi(argv[0]);
    mouseY = atoi(argv[1]);
    buttons = atoi(argv[2]);

    sp.type = SPIN_MOUSE_TYPE;
    sp.u_msg.mouse.x = mouseX;
    sp.u_msg.mouse.y = mouseY;
    sp.u_msg.mouse.buttons = buttons;

    uhWriteGame(u64fd, &sp, sizeof(SpinControl));

    strcpy(interp->result, "SpinTclMouse passed");
    return TCL_OK;
}

int SpinTclModel(ClientData data, Tcl_Interp *interp, int argc, char *argv[])
{
    int i,model;
    SpinControl	sp;
        
    model = atoi(argv[0]);

    sp.type = SPIN_MODEL_TYPE;
    sp.u_msg.model.model = model;

    uhWriteGame(u64fd, &sp, sizeof(SpinControl));
    
    strcpy(interp->result, "SpinTclModel passed");
    return TCL_OK;
}

Gfx dlbuf[2048];

Gfx *SpinTclGetDlistp( void )
{
    return dlbuf;
}

void SpinTclDlist( Gfx *last_addr )
{
    SpinControl  sp;
    int          len;

    len = (last_addr - dlbuf) * sizeof(Gfx);
    sp.type = SPIN_DLIST_TYPE;
    sp.u_msg.dlist.dlsize = len;
    
    uhWriteGame(u64fd, &sp, sizeof(SpinControl));

    uhWriteGame(u64fd, dlbuf, len);  

}


int SpinTclTrap(ClientData data, Tcl_Interp *interp, int argc, char *argv[])
{
    SpinControl	sp;
    int  frames,type;

    frames = atoi(argv[0]);
    type = atoi(argv[1]);

    sp.type = SPIN_TRAP_TYPE;
    sp.u_msg.trap.trap = frames;
    sp.u_msg.trap.type = type;

    /*
     * trap doesnt work in the real hardware
     */
    uhWriteGame(u64fd,&sp, sizeof(SpinControl));

    strcpy(interp->result, "SpinTclTrap passed");
    return TCL_OK;
}

int SpinTclConnect(ClientData data, Tcl_Interp *interp, int argc, char *argv[])
{
    int  reply;
  
    u64fd = uhOpenGame(DEV_U64_DATA); 
    if (u64fd == -1) 
    {
        fprintf(stderr, "Spintcl: Unable to open %s ", DEV_U64_DATA);
	perror("");
	return TCL_ERROR;
    }
    fprintf(stderr, "Listening for game ready signal\n");
    while (1) 
    {
        uhReadGame(u64fd, &reply, 4);

        if (reply  == SPIN_READY)
            break;
    }
    fprintf(stderr, "Received game ready signal\n");
    return TCL_OK;
}

int SpinTclInit(Tcl_Interp *interp)
{
    Tcl_CreateCommand(interp, "SpinTclConnect", SpinTclConnect, NULL, NULL);
    Tcl_CreateCommand(interp, "SpinTclModel", SpinTclModel, NULL, NULL);
    Tcl_CreateCommand(interp, "SpinTclMouse", SpinTclMouse, NULL, NULL);
    Tcl_CreateCommand(interp, "SpinTclTrap", SpinTclTrap, NULL, NULL);
    strcpy(interp->result, "SpinTclInit passed");
    return TCL_OK;
}

/*
 *  Dump display list
 */
int dump_dl( Gfx *uidl)
{
    unsigned int i, cmd;

    /* dump UI display list */
    fprintf(stderr,"\nDump of UI display list:\n\n");
    i = 0;
    do 
    {
        cmd = uidl[i].words.w0;
        cmd = (cmd & 0xff000000) >> 24; 
        switch (cmd)
        {
	    case G_SPNOOP: fprintf(stderr,"%3d: G_SPNOOP\n", i); break;
	    case G_MTX: fprintf(stderr,"%3d: G_G_MTX\n", i); break;
	    case G_MOVEMEM: fprintf(stderr,"%3d: G_VIEWPORT or G_LIGHT (MOVEMEM)\n", i); break;
	    case G_VTX: fprintf(stderr,"%3d: G_VTX\n", i); break;
	    case G_DL: fprintf(stderr,"%3d: G_DL\n", i); break;
	    case 0xbf: fprintf(stderr,"%3d: G_TRI1\n", i); break;
	    case 0xbd: fprintf(stderr,"%3d: G_POPMTX\n", i); break;
	    case 0xbc: fprintf(stderr,"%3d: G_SEGMENT\n", i); break;
	    case 0xb7: fprintf(stderr,"%3d: G_SETGEOMETRYMODE\n", i); break;
	    case 0xb6: fprintf(stderr,"%3d: G_CLEARGEOMETRYMODE\n", i); break;
	    case 0xb5: fprintf(stderr,"%3d: G_LINE3D\n", i); break;
	    case 0xb4: fprintf(stderr,"%3d: G_PERSPNORMALIZE\n", i); break;
	    case 0xb3: fprintf(stderr,"%3d: G_RDPHALF_1\n", i); break;
	    case 0xb2: fprintf(stderr,"%3d: G_RDPHALF_2\n", i); break;
	    case G_NOOP: fprintf(stderr,"%3d: G_NOOP\n", i); break;
	    case G_SETCIMG: fprintf(stderr,"%3d: G_SETCIMG\n", i); break;
	    case G_SETZIMG: fprintf(stderr,"%3d: G_SETMIMG\n", i); break;
	    case G_SETTIMG: fprintf(stderr,"%3d: G_SETTIMG\n", i); break;
	    case G_SETCOMBINE: fprintf(stderr,"%3d: G_SETCOMBINE\n", i); break;
	    case G_SETENVCOLOR: fprintf(stderr,"%3d: G_SETENVCOLOR\n", i); break;
	    case G_SETPRIMCOLOR: fprintf(stderr,"%3d: G_SETPRIMCOLOR\n", i); break;
	    case G_SETBLENDCOLOR: fprintf(stderr,"%3d: G_SETBLENDCOLOR\n", i); break;
	    case G_SETFOGCOLOR: fprintf(stderr,"%3d: G_SETFOGCOLOR\n", i); break;
	    case G_SETFILLCOLOR: fprintf(stderr,"%3d: G_SETFILLCOLOR\n", i); break;
	    case G_FILLRECT: fprintf(stderr,"%3d: G_FILLRECT\n", i); break;
	    case G_SETTILE: fprintf(stderr,"%3d: G_SETTILE\n", i); break;
	    case G_LOADTILE: fprintf(stderr,"%3d: G_LOADTILE\n", i); break;
	    case G_LOADBLOCK: fprintf(stderr,"%3d: G_LOADBLOCK\n", i); break;
	    case G_SETTILESIZE: fprintf(stderr,"%3d: G_SETTILESIZE\n", i); break;
	    case G_LOADTLUT: fprintf(stderr,"%3d: G_LOADTLUT\n", i); break;
	    case G_RDPSETOTHERMODE: fprintf(stderr,"%3d: G_RDPSETOTHERMODE\n", i); break;
	    case G_SETPRIMDEPTH: fprintf(stderr,"%3d: G_SETPRIMDEPTH\n", i); break;
	    case G_SETSCISSOR: fprintf(stderr,"%3d: G_SETSCISSOR\n", i); break;
	    case G_SETCONVERT: fprintf(stderr,"%3d: G_SETCONVERT\n", i); break;
	    case G_SETKEYR: fprintf(stderr,"%3d: G_SETKEYR\n", i); break;
	    case G_SETKEYGB: fprintf(stderr,"%3d: G_SETKEYGB\n", i); break;
	    case G_RDPFULLSYNC: fprintf(stderr,"%3d: G_RDPFULLSYNC\n", i); break;
	    case G_RDPTILESYNC: fprintf(stderr,"%3d: G_RDPTILESYNC\n", i); break;
	    case G_RDPPIPESYNC: fprintf(stderr,"%3d: G_RDPPIPESYNC\n", i); break;
	    case G_RDPLOADSYNC: fprintf(stderr,"%3d: G_RDPLOADSYNC\n", i); break;
	    case G_TEXRECTFLIP: fprintf(stderr,"%3d: G_TEXRECTFLIP\n", i); break;
	    case G_TEXRECT: fprintf(stderr,"%3d: G_TEXRECT\n", i); break;
	    case 0xb8: fprintf(stderr,"%3d: G_ENDDL\n", i); break;
	    case 0xbb: fprintf(stderr,"%3d: G_TEXTURE\n", i); break;
	    case 0xba: fprintf(stderr,"%3d: G_SETOTHERMODE_H\n", i); break;
	    case 0xb9: fprintf(stderr,"%3d: G_SETOTHERMODE_L\n", i); break;
	    default: fprintf(stderr,"%3d: command %d not recognized\n", i, cmd); break;
        }
        fprintf(stderr,"W0 %08x w1 %08x\n", uidl[i].words.w0, uidl[i].words.w1);
        i++;
    }  while (cmd != 0xb8 && i < 100);
}