main.c 2.51 KB
/*============================================================================

		NINTENDO64 TECHNICAL SUPPORT CENTER 
		
		    NINTENDO64 SAMPLE PROGRAM 2

		Copyright (C) 1997, NINTENDO Co,Ltd.

============================================================================*/

#include <ultra64.h>
#include <PR/ramrom.h>
#include <assert.h>

#include "def.h"
#include "vram.h"
#include "segment.h"
#include "message.h"
#include "nnsched.h"
#include "main.h"
#include "controller.h"
#include "audio.h"
#include "graphic.h"


NNSched sched;
int main_no;

/* 外部関数宣言 */
extern int main00(NNSched* );


/*------------------------
	mainproc
--------------------------*/
void mainproc(void* arg)
{

  /* initialize audio */
  auAudioInit();

  /* initialize sequence player */
  auSeqPlayerInit(_midibankSegmentRomStart, _midibankSegmentRomEnd,
		  _seqSegmentRomStart, _seqSegmentRomEnd,
		  _miditableSegmentRomStart);

  /* initialize sound player */
  auSndPlayerInit(_sfxbankSegmentRomStart, _sfxbankSegmentRomEnd,
		  _sfxtableSegmentRomStart);


  /* create scheduler thread */
  nnScCreateScheduler(&sched, OS_VI_NTSC_LAN1, 1);

  /* create audio thread */
  auCreateAudioThread(&sched);

  /* graphic library の初期化 */
  gfxInit(_gfxdlistSegmentStart);

  /* craete graphic thread */
  gfxCreateGraphicThread(&sched);

  /*
     VIインターフェイスの設定
     OS_VI_DITHER_FILTER_ONを指定することでDITHERフィルターを使用できるように
     する。
  */
  osViSetSpecialFeatures( OS_VI_DITHER_FILTER_ON | OS_VI_GAMMA_OFF
			 | OS_VI_GAMMA_DITHER_OFF);

  /* initialize controller (use max 4 controller)*/
  controllerInit(4);
  controllerThreadMake(&sched);

  main_no = MAIN_00;

  osThreadProfileInit();               /* <===== プロファイル用に追加 */

  /* game main loop */
  while(1){

    osThreadProfileStart();            /* <===== プロファイル用に追加 */

    switch(main_no){
    case MAIN_00:   /* main 00 */
      main_no = main00(&sched);
      break;
    case MAIN_01:   /* main 01 */
      break;
    case MAIN_02:
      break;
    case MAIN_03:
      break;
    case MAIN_04:
      break;
    }
    
    osThreadProfileStop();             /* <===== プロファイル用に追加 */
    
    /* thread profile の結果表示を追加 */
    {
	int i;
	u64 temp_time;
	for(i=0;i<THPROF_IDMAX;i++){
	    if (temp_time = osThreadProfileReadTime(i)){
		osSyncPrintf("id = %3d , count = %8d , time = %12lluusec\n",i,
			     osThreadProfileReadCount(i),OS_CYCLES_TO_USEC(temp_time));
	    }
	}
	osSyncPrintf("-------------------\n");
    }
    
  }  /* end of while */
}