/*--------------------------------------*/ /* */ /* BASLIB */ /* */ /*--------------------------------------*/ #include #include "baslib.h" #define OT_LENGTH 10 volatile u_char *padb[3]; int act; GsOT ot[2]; GsOT_TAG ott[2][1 << OT_LENGTH]; PACKET pac[2][2000 * 24]; static char sc[28][36]; int sx,sy; /*--------------------------------------*/ sc_init() { GsInitGraph(320, 240, GsNONINTER | GsOFSGPU, 0, 0); GsDefDispBuff(0, 0, 0, 240); GsInit3D(); GsSetProjection(320); } void VIEW(int x1, int y1, int z1, int x2, int y2, int z2) { GsRVIEW2 v; v.vpx = x1<<6; v.vpy = y1<<6; v.vpz = -z1<<6; v.vrx = x2<<6; v.vry = y2<<6; v.vrz = -z2<<6; v.rz = 0; v.super = WORLD; GsSetRefView2(&v); } light_init() { GsF_LIGHT lt; lt.vx = 2; lt.vy = 4; lt.vz = 1; lt.r = 0xff; lt.g = 0xff; lt.b = 0xff; GsSetFlatLight(0, <); // GsSetFlatLight(1, <); // GsSetFlatLight(2, <); GsSetAmbient(1024, 1024, 1024); GsSetLightMode(0); } void INIT() { model_init(); sc_init(); VIEW(160, -200, 300, 160, 0, 160); light_init(); FntLoad(960, 256); FntOpen(-144, -104, 36*8, 28*8, 0, 36*28); GetPadBuf(&padb[1], &padb[2]); padb[0]=padb[1]; ot[0].length = OT_LENGTH; ot[0].org = ott[0]; ot[1].length = OT_LENGTH; ot[1].org = ott[1]; CLS(); vsync2(); } /*--------------------------------------*/ vsync2() { act = GsGetActiveBuff(); GsSetWorkBase(pac[act]); GsClearOt(0, 0, &ot[act]); } void VSYNC() { FntPrint( sc ); FntFlush(-1); DrawSync(0); VSync(0); // ResetGraph(1); GsSwapDispBuff(); GsSortClear(0, 0, 0, &ot[act]); GsDrawOt(&ot[act]); vsync2(); } /*--------------------------------------*/ #define MODEL_ADDR 0x80090000 u_long *tmd = (u_long *)MODEL_ADDR; model_init() { tmd++; GsMapModelingData(tmd); tmd += 2; } void POLYGON(int x, int y, int z, int k, int n) { GsDOBJ2 obj2; GsCOORDINATE2 coo2; SVECTOR svec; MATRIX tmat; GsInitCoordinate2(WORLD,&coo2); svec.vx = 0; svec.vy = k; svec.vz = 0; RotMatrix(&svec, &coo2.coord); coo2.flg = 0; obj2.attribute = 0; obj2.coord2 = &coo2; GsLinkObject4((u_long)tmd, &obj2, n); coo2.coord.t[0] = x<<6; coo2.coord.t[1] = y<<6; coo2.coord.t[2] = -z<<6; coo2.flg = 0; GsGetLw(&coo2, &tmat); GsSetLightMatrix(&tmat); GsGetLs(&coo2, &tmat); GsSetLsMatrix(&tmat); GsSortObject4(&obj2, &ot[act], 14 - OT_LENGTH, getScratchAddr(0)); } /*--------------------------------------*/ void PRINT(char *c) { while (*c != 0) sc[sy][sx++] = *c++; } void print2(char *c) { sc[sy][sx++] = *c; } void LOCATE(int x, int y) { sx = x; sy = y; } void CLS() { int i,j; for (i=0; i<28; i++) for (j=0; j<36; j++) sc[i][j] = ' '; sx = sy = 0; } char *itoa(int ii) { int i = 15; static char a[16]; a[i] = 0; if (ii >= 0) do{ a[--i] = (ii % 10) + '0'; ii = ii / 10; } while(ii > 0); else { ii = -ii; do{ a[--i] = (ii % 10) + '0'; ii = ii / 10; } while (ii > 0); a[--i] = '-'; } return &a[i]; } /*-------------------------------------------*/ int STICK(int j) { int joy; int joyd[16] = { 0, 0, 0, 1, 0, 0, 7, 4, 0, 3, 0, 2, 9, 6, 8, 0 }; joy = *(padb[j]+2) >> 4; return joyd[joy]; } int STRIG(int j) { int joy; joy = *(padb[j]+2) << 8 | *(padb[j]+3); return ~joy & 0x0fff; } /*-------------------------------------------*/