#include #include #include "action.h" #include "vsync.h" volatile long VScnt=0; volatile u_char *bb0,*bb1; volatile short pad1[60],pad2[60]; volatile short *P1ptr,*P2ptr; volatile short DrawFlag; /*---------------------------------------------------------------------- マクロ ----------------------------------------------------------------------*/ /* 基本設定 */ #define OT_LENGTH 4 /* オーダリングテーブルの数 */ #define MAXOBJ 100 /* スプライト(へんなやつ)数の上限 */ /* 表示領域関連マクロ */ #define FRAME_X 320 /* 表示領域サイズ(横) */ #define FRAME_Y 240 /* 表示領域サイズ(縦) */ #define WALL_X (FRAME_X-16) /* ボールパタン可動領域サイズ(横) */ #define WALL_Y (FRAME_Y-16) /* ボールパタン可動領域サイズ(縦) */ /* 範囲チェックマクロ */ #define limitRange(x, l, h) ((x)=((x)<(l)?(l):(x)>(h)?(h):(x))) /* BG情報 */ #define N_BG 1 /* 用意するBGの枚数 */ #define CEL_ADDR 0x80120000 /* セルデータ先頭アドレス */ #define BGWSIZE (((320/16+1)*(240/16+1+1)*6+4)*2+2) /* 反転情報 */ #define X_REV (0x01<<23) #define Y_REV (0x01<<22) /*---------------------------------------------------------------------- グローバル ----------------------------------------------------------------------*/ /* オーダリングテーブル関連変数 */ GsOT WorldOT[2]; GsOT_TAG OTTags[2][1<speed++ > cw->maxspd ) { cw->posX += cw->vectX; if (cw->count++ > 288){ ActWork[ActNum].fnAction = testfunc0_1; cw->vectX = -1; cw->vectY = 0; cw->count = 0; } cw->speed = 0; cw->sp = &sprt[cw->ctAnm + (cw->count&0x01)]; cw->sp->attribute&=~X_REV; } cw->sp->x = cw->posX; cw->sp->y = cw->posY; GsSortSprite(cw->sp, &WorldOT[activeBuff], 0); } void testfunc0_1( void ){ ChrAct *cw; cw = (ChrAct *)S_PAD; if ( cw->speed++ > cw->maxspd ){ cw->posX += cw->vectX; if (cw->count++ > 288){ ActWork[ActNum].fnAction = testfunc0; cw->vectX = 1; cw->vectY = 0; cw->count = 0; } cw->speed = 0; cw->sp = &sprt[cw->ctAnm + (cw->count&0x01)]; cw->sp->attribute|=X_REV; } cw->sp->x = cw->posX; cw->sp->y = cw->posY; GsSortSprite(cw->sp, &WorldOT[activeBuff], 0); } /*---------------------------------------------------------------------- タスク0初期化(まとめて) ----------------------------------------------------------------------*/ void initfunc0( ChrAct *cp ){ short i,aptn; for ( aptn=0, i=0; i<7; aptn+=2,i++ ){ /* とりあえず7匹いってみっか */ /* 各種パラメータの設定(ほんとはデータファイルとかから取って来る) */ cp->count = 0; cp->flags = 0; cp->posX = 0; cp->posY = i*32; cp->vectX = 1; cp->vectY = 0; cp->speed = 0; cp->maxspd = (i+1)*2; cp->ctAnm = aptn; cp->sp->x = cp->posX; cp->sp->y = cp->posY; cp->sp = &sprt[aptn]; SetAction( testfunc0, cp, sizeof(*cp)); cp++; } } /*---------------------------------------------------------------------- TIMをフレームバッファへ in : u_long TIM格納ポインタ out: GsIMAGE イメージデータ構成情報 ----------------------------------------------------------------------*/ GsIMAGE* PutTIM( u_long *ptTIM ){ GsIMAGE *tim; RECT rect; GsGetTimInfo(ptTIM+1, tim); rect.x = tim->px; rect.y = tim->py; rect.w = tim->pw; rect.h = tim->ph; LoadImage(&rect, tim->pixel); /* CLUTをフレームバッファへ */ if ((tim->pmode>>3)&0x01){ rect.x = tim->cx; rect.y = tim->cy; rect.w = tim->cw; rect.h = tim->ch; LoadImage(&rect,tim->clut); } return ( tim ); } /*----------------------------------------------------------------------  スプライト初期化 ----------------------------------------------------------------------*/ static void init_sprite( void ){ GsSPRITE *sp; GsIMAGE *tim; u_short sp_tpage; RECT rect; int i; tim = PutTIM((long *)0x80110000 ); /* スプライトをフレームバッファに */ sp_tpage = GetTPage(0, 0, tim->px, tim->py); /* スプライトの初期化 */ for (sp = sprt, i = 0; i < MAXOBJ; i++, sp++) { sp->attribute = 0x00000000; sp->x = 0; sp->y = 0; sp->w = 32; sp->h = 32; sp->tpage = sp_tpage; sp->u = 32*(i&0x03); sp->v = 0; sp->cx = tim->cx; sp->cy = tim->cy; sp->r = sp->g = sp->b = 0x80; sp->mx = 0; sp->my = 0; sp->scalex = ONE; sp->scaley = ONE; sp->rotate = 0; } } /*----------------------------------------------------------------------  BG初期化 ----------------------------------------------------------------------*/ static void init_BG( void ){ static GsCELL cell[256]; /* CELLデータデッチ上げ用 */ u_short cba; u_short tpage; GsIMAGE *tim; int i,j; GsCELL *pcel; tim = PutTIM((long *)0x80120000 ); /* BGをフレームバッファに */ tpage = GetTPage( 0, 0, tim->px, tim->py ); cba = ( tim->cy<<6 )|( tim->cx>>4 ); /* CELデータをデッチあげる */ pcel = cell; for ( i=0; i<16; i++ ){ for ( j=0; j<16; j++ ){ pcel->u = j*16; pcel->v = i*16; pcel->cba = cba; pcel->flag = 0; pcel->tpage = tpage; pcel++; } } /* MAPデータをデッチあげる */ BGMap[0].ncellw = 128; /* MAPの大きさ */ BGMap[0].ncellh = 128; BGMap[0].cellw = 16; /* セルの大きさ */ BGMap[0].cellh = 16; BGMap[0].index = bgd; /* マップ本体 */ BGMap[0].base = cell; /* セル配列へのポインタ */ /* 作業領域(Primitiveエリア)の確保&初期化 */ BGWork[0] = BGPacket+0*BGWSIZE; GsInitFixBg16( &BGData[0], BGWork[0] ); /* その他(attribute類) */ BGData[0].attribute = (0<<24)|GsROTOFF; BGData[0].scrollx = 0; BGData[0].scrolly = 0; BGData[0].r = BGData[0].g = BGData[0].b = 128; BGData[0].map = &(BGMap[0]); } /*---------------------------------------------------------------------- めいん ----------------------------------------------------------------------*/ void main( void ){ GsOT *ot; /* 描画対象OTへのポインタ */ int i,cnt; GetPadBuf( &bb0,&bb1); P1ptr = pad1; P2ptr = pad2; VSyncCallback( VSfunc ); ExitCriticalSection(); GsInitGraph(320, 240, 4, 0, 0); /* 描画・表示環境の設定 */ GsDefDispBuff(0, 0, 0, 240); /* 同上 */ /* オーダリングテーブル情報の設定 */ for (i = 0; i < 2; i++) { WorldOT[i].length = OT_LENGTH; WorldOT[i].org = OTTags[i]; } FntLoad(960, 256); /* 基本フォントパターンをフレームバッファにロード */ FntOpen(16, 16, 256, 200, 0, 512); /* フォントの表示位置の設定 */ init_sprite(); bgd = malloc( (short)(128*128) ); bzero( bgd, 128*128 ); init_BG(); InitAct(); initfunc0( &ChrWork[0] ); /* メインループ */ while ( (*P1ptr & 0x0100)==0 ) { /* ダブルバッファの切り替え */ activeBuff = GsGetActiveBuff(); GsSetWorkBase((PACKET *)GpuPacketArea[activeBuff]); /* オーダリングテーブルのクリア */ GsClearOt( 0, 0, &WorldOT[activeBuff] ); GoAction(); /* BG描画 */ GsSortFixBg16( BGData, BGWork[0], &WorldOT[activeBuff], 1 ); DrawSync(0); /* 描画の終了待ち */ VSync(0); GsSwapDispBuff(); /* OTに登録されたプリミティブの描画開始 */ GsDrawOt( &WorldOT[activeBuff] ); FntPrint( "%d,%x\r", (short)VScnt,(short)*P1ptr ); FntFlush( -1 ); } EnterCriticalSection(); VSyncCallback( NULL ); free(bgd); }