/*
	Ninja Sample

	COPYRIGHT (C) SEGA ENTERSRISES,LTD.

	Sample

	1997.10.20
*/
#include <Ninjawin.h>

/* Setitng to map.c */
extern Uint32 jimenmap[4][7];
extern NJS_TEXLIST jimentexlist;
extern Uint32 temaemap[4][7];
extern NJS_TEXLIST temaetexlist;

NJS_SCROLL jimenScl;
NJS_SCROLL temaeScl;

NJS_PERIPHERAL *per;
NJS_TEXMEMLIST texmemlist[100];

void njUserInit(void)
{

    /* System Initialization */
	njInitSystem( NJD_RESOLUTION_VGA, NJD_FRAMEBUFFER_MODE_RGB555, 1 );
	njInitVertexBuffer( 10000, 0, 10000, 0 );

    /* Registering Cells */
    njInitTexture(texmemlist,100);
    njSetTexturePath(".\\usiro\\");
	njLoadTexture(&jimentexlist);
    njSetTexturePath(".\\mae\\");
	njLoadTexture(&temaetexlist);

    /* Setting scrolls */
    jimenScl.celps = 128;			/* cell size               */
    jimenScl.mapw = 7;				/* number of cells in map width   */
    jimenScl.maph = 4;				/* number of cells in map height   */
    jimenScl.sx = 1.0f;				/* width scale              */
    jimenScl.sy = 1.0f;				/* height scale              */
    jimenScl.spx = 0.f;				/* scale center x-coordinate  */
    jimenScl.spy = 0.f;				/* scale center y-coordinate  */
    jimenScl.list = &jimentexlist;  /* texture list         */
    jimenScl.map = (Uint32*)jimenmap;  /* map array               */
    jimenScl.mflag = OFF;			/* matrix flag       */
    jimenScl.sflag = OFF;			/* scale flag           */
    jimenScl.pr = -1000.f;			/* priority           */
    jimenScl.px = 0.f;				/* move x-coordinate    */
    jimenScl.py = 0.f;				/* move y-coordinate    */
    jimenScl.bx = 0.f;				/* map starting point x-coordinate */
    jimenScl.by = 0.f;				/* map starting point y-coordinate */
    jimenScl.cx = 0.f;				/* rotation center x-coordinate */
    jimenScl.cy = 0.f;				/* rotation center y-coordinate */
    jimenScl.sclc.argb.a = 255;		/* default alpha            */
    jimenScl.sclc.argb.r = 255;		/* default red              */
    jimenScl.sclc.argb.g = 255;		/* default green            */
    jimenScl.sclc.argb.b = 255;		/* default blue             */
    jimenScl.colmode = NJD_COLOR_MODE_PACKED_TEXTURE;   /* setting color mode */

    /* setting scroll */
    temaeScl.celps = 128;			/* cell size               */
    temaeScl.mapw = 7;				/* number of cells in map width   */
    temaeScl.maph = 4;				/* number of cells in map height  */
    temaeScl.sx = 1.0f;				/* scale width              */
    temaeScl.sy = 1.0f;				/* scale height             */
    temaeScl.spx = 0.f;				/* scale center x-coordinate */
    temaeScl.spy = 0.f;				/* scale center y-coordinate */
    temaeScl.list = &temaetexlist;  /* texture list             */
    temaeScl.map = (Uint32*)temaemap;  /* map array             */
    temaeScl.mflag = OFF;			/* matrix flag      */
    temaeScl.sflag = OFF;			/* scale flag           */
    temaeScl.pr = -900.f;			/* priority           */
    temaeScl.px = 0.f;				/* move x-coordinate  */
    temaeScl.py = 0.f;				/* move y-coordinate  */
    temaeScl.bx = 0.f;				/* map starting point x-coordinate */
    temaeScl.by = 0.f;				/* map starting point y-coordinate */
    temaeScl.cx = 0.f;				/* center of rotation x-coordinate */
    temaeScl.cy = 0.f;				/* center of rotation y-coordinate */
    temaeScl.sclc.argb.a = 255;		/* default alpha      */
    temaeScl.sclc.argb.r = 255;		/* default red          */
    temaeScl.sclc.argb.g = 255;		/* default green        */
    temaeScl.sclc.argb.b = 255;		/* default blue         */
    temaeScl.colmode = NJD_COLOR_MODE_PACKED_TEXTURE_TRANS;   /* setting color mode */

}

Sint32 njUserMain(void)
{
    per = njGetPeripheral(NJD_PORT_SYSKEYBOARD);

	temaeScl.bx += 4.0f;
    if(temaeScl.bx > temaeScl.celps*temaeScl.mapw)
        temaeScl.bx -= temaeScl.celps*temaeScl.mapw;

    jimenScl.bx -= 2.0f;
    if(jimenScl.bx > jimenScl.celps*jimenScl.mapw)
        jimenScl.bx -= jimenScl.celps*jimenScl.mapw;

	njDrawScroll(&jimenScl);
	njDrawScroll(&temaeScl);

    if(per->on & NJD_DGT_ST){
        return NJD_USER_EXIT;
    }

	njPrintC(NJM_LOCATION(4,4),"SCROLL TEST");

    return NJD_USER_CONTINUE;
}


void njUserExit(void)
{
    njExitTexture();
    njExitSystem();
}