top.c

来自「ESS3890+SL原代码(1*16内存)」· C语言 代码 · 共 2,300 行 · 第 1/4 页

C
2,300
字号
	    CG_service(1);
#else
	    OSD_schedule_check();
#endif

	    if (count & 0x20) { /* 1/8 of count & 7 = 0 */
		/* service frequency is ~10 per sec..
		 * if your task doesn't need to be called more
		 * frequently than this put it here.
		 */
		VBV_update_occupancy(VBV_fullness);
		spoolkeyvar(&VBV_fullness);
		ABV_update_occupancy(ABV_fullness);
		spoolkeyvar(&ABV_fullness);
		PCM_update_occupancy(PCM_fullness);
		spoolkeyvar(&PCM_fullness);
#ifdef ANTI_SHOCK
		AS_ABV_update_occupancy(AS_ABV_fullness);
		spoolkeyvar(&AS_ABV_fullness);
#endif
#ifdef MP3
		if ((STREAM_type == MP3_ID)
#ifdef WMA_DEC
		    || (STREAM_type == WMA_ID)
#endif
		    ) {
#ifdef ANTI_SHOCK
		    AS_ABV_fullness = ABV_fullness;
#endif
		    MP3_VBR_gain_adjust(ABV_fullness);
		}
#endif
	        if (tsk_timer < glbTimer) {
		    /* service freq: ~2Hz ...
		     * using glbTimer reference gives more regular service
		     * frequency than "count".
		     */

#ifdef PLAY20
		    /* 1)updates time display variables for VFD/OSD
		     * 2)"spins" VFD wheel if present..
		     *  (NOTE: if service freq. is too high the VFD wheel
		     *         will spin very fast!)
		     */
		    updateLCDtime();
#endif
		    /* Reduce frequency of VBV_alarm and
		     * vcx_pause_ack checking.
		     */
#ifdef ABNORMAL_VCD
		    if (abnormal_vcd & TRACK_IS_ABVCD) {
		        VBV_alarm = 0;
		    } else
#endif
	            {
#ifdef VCDLC
		        VBV_alarm = 2560;
#else
		        VBV_alarm = 1792;
#endif
		    }
		    if (vcx_pause && (vcx_pause_ack == 0)) {
		        vcx_pause_ack = 1;
		    }

		    tsk_timer = glbTimer + 25; /* a bit more than 2Hz */
	        }
	    }
	}
	break;

    case 1:
#ifdef DIGEST
	if (vcx_digest)
	    decideDigestVideoOrAudio();
	else
#endif
	{
#ifdef DATA_CD
	    if (STREAM_type
#ifdef AVI_DEC
	       	&& (STREAM_type != AVI_ID)
#endif
	    ) {
		/* more frequent buffer monitoring for MP3, WMA or JPEG */
		video_state_machine();
	    } else
#endif
#ifdef ZOOM
	    /* do zoom when necessary */
	    if (!VID_decoding_in_progress && !end_of_still &&
		expect_zoom) {
		if (vcx_VertSz <= 288) {
		    zoom_reset();
		    set_zoom();
		}
		expect_zoom = 0;
	    }
#endif
	    /* TV change not allowed for digest */
	    DISP_TV_service();

#ifdef FRACTINT
	    if (FRACT_display_on) FRACT_set_palette();
#endif
	}
	break;

    case 2:
#if defined(TCSERVO) || defined(GDTSERVO) || defined (SERVO)
	SERVO_service((count & 0x8)); /* 1/2 of count & 7 = 2 to check SubQ */
#else
#ifdef PLAY20
	receive_dsa();	/* to prevent losing key/CD info */
#endif
#endif

#if defined(CDG) && defined(VCDLC)
#ifdef DEMUX_ON_FLY
	if (cdg_data_is_ready) {
	    DISP_frame = disp_frame = 2;
	}
#endif
	if (cdg_code_ready) {
	    CDG_main();
	    if (cdg_data_is_ready) CDG_show();
	}
#endif
	break;

    case 3:
    case 7:
#ifdef ERROR_CONCEALMENT
	if (STREAM_type || TDM_isCDDA) break; /* Do it only for VCD disc */
#if defined(DSC_ENABLE_C2PO) && defined(USE_C2PO_MODE)
        C2PO_error_mode();
#else
	cust_error_mode();
#endif
#endif
	break;

    case 4:
	if (0
#ifdef DATA_CD
	    || (STREAM_type
#ifdef AVI_DEC
		 && (STREAM_type != AVI_ID)
#endif
		)
#endif
#ifdef ANTI_SHOCK
	     || PLAY_set_2x_speed
#endif
        ) {
	    video_state_machine();
	} else {

	    /* more frequent for faster TV mode change in VCD FF/FR */
#ifdef DIGEST
	if (vcx_digest)
#endif
	    DISP_TV_service();
	}
	break;

    case 5:

	/*
	 * When there is a voltage spike, our TDM may get out of sync and
	 * start to latch the wrong data. In which case, there will be
	 * no valid incoming data and the system will hang.
	 *
	 * The following check looks for this condition and restarts TDM to
	 * recover from this situation.
	 *
	 * NOTE: For VCD anti-shock, we may also get here for scratched
	 * discs, after longjump and XPORT_active gets out of sync.
	 */
	if (!TDM_isCDDA && XPORT_active) {
	    PRIVATE unsigned int next_tdm_check_timer;
	    PRIVATE int last_tdm_int_counter;

	    if (glbTimer > next_tdm_check_timer) {
		if (TDM_cntInterrupt == last_tdm_int_counter) {
		    /* This is BAD! TDM may be out of sync. */
		    if (vcx_xfer_mode == 5) TDM_turn_on();
#if defined(ABNORMAL_VCD) || defined(ANTI_SHOCK)
		    if (video_state == VIDEO_ABNORMAL) XPORT_active = 0;
#endif
		}
		next_tdm_check_timer = glbTimer + 10;	/* ~.2 second */
		last_tdm_int_counter = TDM_cntInterrupt;
	    }
	}

#ifdef PLAY20
	/* If we have key pending, we should process it ASAP. */
	if (microKeyPending() || wait_pause)
	    CUST_background();
#endif

	break;

    case 6:
	if (count & 0x8) { /* 1/2 of count & 7 = 6 */
#ifdef SERVO
	    SERVO_mode_handle();
#endif
#if defined(TCSERVO) || defined(GDTSERVO) || defined(SERVO) || defined(SILAN_SERVO)
	    /* for SERVO(not DSA), OSD update and CDDA track change */
	    receive_dsa();
#endif
	}
	break;
    }

#if defined(JPEG_DEC) && defined(FLESHTONE)
    if (is_jpeg && (!FJ_map.dir) &&
	fleshtone_proc && (!JpgFleshtoneVscale))
        Fleshtone_JPG_UVProc();
#endif
#if 0
#if defined(CDG) && !defined(ANTI_SHOCK)
    if (TDM_isCDDA || MP3CDG_started) {
	CDG_main();
	if (cdg_data_is_ready) CDG_show();
    }
#endif
#endif
}

/***************************************************************************
 Background tasks.
 ***************************************************************************/
void TSK_background()
{
    extern int picture_done;

    /* Checking when picture is *done* should be here in
     * the lower priority TSK_background().
     */
    if (picture_done) end_of_still = 0;
    else if (end_of_still == 2) {
	processEndOfStill();
	end_of_still = 1;
    }
    if (picture_type == 0xe0) {
	if (end_of_sequence && !b7_already_flushed) {
	    processEndOfStill();
	    b7_already_flushed = 1;
	}
    }

    if (PTS_xsit>0) process_pts();

#ifdef SCR_SAVER
    process_scr_saver();
#endif
#ifdef MIC_RECORD
    if (REC_mode != REC_OFF) {
        if (TDM_isCDDA) REC_PTS_aud = AUD_n_frames;
    }

    if (TDM_trigger == 3 && (REC_mode != REC_OFF)) {
        if ( vcx_big >= VBV_fullness) {
            if ( ready_to_switch == 1 && vcx_scn_vscale) ready_to_switch = 0;
            TDM_trigger = 1;
        } else if ( 2*vcx_big >= VBV_fullness) {
            if (!(VID_decoding_in_progress || ready_to_switch) )
                TDM_trigger = 1;
        }
    }
#endif

#ifdef FRACTINT
    if (FRACT_process_on) FRACT_paint_a_block();
#endif

    CUST_background();

#ifdef DEBUG
    if (dbg_console) {
	DBG_console();
	dbg_console = 0;
    }
#endif

#ifdef FADE
    if (FADE_in_process) Fade();
#endif

#if defined(CDG) && !defined(ANTI_SHOCK)
    if( TDM_isCDDA || MP3CDG_started) {
        if (cdg_show_cnt&0x01)CDG_main();
        if(cdg_data_is_ready && !(cdg_show_cnt&0x01)) CDG_show();
        if( cdg_show_cnt++ >= 4) cdg_show_cnt = 0;
     }
#endif
    VCX_service();
}

/***************************************************************************
  Process flush request
 ***************************************************************************/
#ifdef JPEG_DEC
void    flush_video_if_possible()
{
    if (VBV_fullness < VBV_size-3*VBV_write) {
        /* If we're no longer playing, we do an input flush so that
           if the last video sector happens to be the very last sector,
           we don't lose the last 4 bytes.
        */
#ifdef IDE
        VBV_flush_gateway(DISC_ready()!=DISC_PLAYING, 0);
#else
        VBV_flush_gateway();
#endif
        DBG_log_pic(6, 19, VBV_wrptr, 0, 0, 0);
        flush_thy_video = 1;
        vcx_big = -1;
    }
}
#endif JPEG_DEC

#ifdef MZOOM
#if 0
int in          = 0,
    out         = 0,
    up          = 0,
    down        = 0,
    right       = 0,
    left        = 0;
#endif
#endif
/***************************************************************************
 The main task.
 ***************************************************************************/
#ifdef TRACE_MP3_AUDIOBREAK
int task_buf[20], task_cnt = 0;
#endif
static void TSK_main()
{
    int	xport_type;

#ifdef DSC
    /* If we are in power down mode, stay here! */
    if (IS_POWER_DOWN) {
	while (1) {
	    TSK_background_high_priority();
	    TSK_background();
#ifdef REAL_CLOCK
	    realClkVFD();
#endif
	}
    }
#endif

    enable_int(vout);
    enable_int(buscon);
    enable_int(xport);

#if (CXDSERVO || MSERVO || SAM_SRV || GDTSERVO || ESS3721)
    RISC_start_timer1();
#endif

    system_reset();

    /* Show logo */
    show_mpeg_still(0xe1, powerupScreen, T_powerupScreen_SZ>>2);
#ifdef SILAN_SERVO
    SERVO_init();
   //SERVO_reset();
#endif

#ifdef DSC
    /* If power on, send pull low to reset CD */
    RESET_CD_LOW;
#endif

    /* Select and initialise input.
       Rely on vcx_bistream_type and vcx_xfer_mode */

    xfer_mode = XFER_init(-1);
    xport_type = XPORT_init(-1, xfer_mode);

    DBG_start_tracing();

    VBV_ABV_set_parameters(xfer_mode);

    /* Start the xport and various buscons. TDM has to be the last to start */
    system_start();

#ifdef ECHO
    MIX_init();
    MIX_start_take_out();
#else
#ifdef ZERO_BUFFER
    /*
     * When zero buffer is used, we only do PCM_start_take_out once
     * at the very beginning.
     */
    PCM_start_take_out();
#endif
#endif


    XPORT_restart_at(XPORT_OFFSET_FUZZY_PLAY, 0);
    XFER_start(xfer_mode);

#ifdef WATCHDOG
    if (setjmp(err_buf)) {
      /*
       * reinitialise registers
       */
      register int foo = 0xc3;
      int xportpc;

      /* Get XPORT PC early since it changes when we reset XPORT! */
      xportpc = mvd[xport_read_status] & 0x7f;
      mvd[riface_irqsuppress] = 0;
      asm("nop"); asm("nop");
      asm volatile("movtos %0,psw" : :"r" (foo));

      jumpCDtime = currCDtime;	/* Record this for debugging!! */
      current_task = 0;
      do_blank = done_blank = 0;

      /*
       * Kill r2b so we'll not hang inside buscon_wait in case we were
       * doing OSD before long jump
       */
      buscon_zap(r2b);
#ifdef ECHO
      buscon_zap(d2a);
      MIX_out = 0;
#else
#ifdef ZERO_BUFFER
      buscon_zap(d2a);
      PCM_starved = 1;
#endif
#endif

      /* Kill VP buscon DMA. */
      buscon_disable(vp);

      hardware_reset(1); /* since current system_reset() doesn't call it */
      system_reset();

      /*
       * Without initializing gateway, we may get into a strange state
       * that video/audio keeps on decoding, but screen has checker board
       * and audio is broken.
       */
      LOW_init_gateway();

#ifdef ECHO
      LOW_init_audio();
#else
#ifdef ZERO_BUFFER
      LOW_init_audio();
#endif
#endif
#ifdef DSC
      DSC_set_audio_sampling_frequency(prev_sampling_frequency);
#endif
      system_start();

#ifdef ECHO
      MIX_init();
      MIX_start_take_out();
#else
#ifdef ZERO_BUFFER
      PCM_start_take_out();
#endif
#endif

      if (TDM_isCDDA)
	  XPORT_restart_at(XPORT_OFFSET_PLAY_CDDA, 1);
      else {
	  /*
	   * For safety, 2.0 machines will check whether the XPORT was
	   * stopped when longjump occurs. If XPORT was in STOP_STATE,
	   * then don't bother to restart XPORT; otherwise, we may
	   * have the strange behavior of having "slide show" when we intend
	   * to show one slide.
	   */
	  if (xportpc != XPORT_OFFSET_STOP_STATE)
	    XPORT_restart_at(XPORT_OFFSET_FUZZY_PLAY, 0);
      }
      XFER_start(xfer_mode);

      EPRINTF(("WATCH DOG RESET!\n"));
    }
#endif

#ifdef FRACTINT
    if (xport_type == AUDIO_ELM_ONLY) {
    	FRACT_start();
    }
#endif

#ifdef KEYDEBUG
    dram_at_0 = *((int *)0x12000000);
#endif

    do {
#ifdef TRACE_MP3_AUDIOBREAK
        task_buf[task_cnt] = current_task;
        task_cnt++;
        if (task_cnt > 19) task_cnt = 0;
#endif
#ifdef AVI_DEC
        if ((STREAM_type == AVI_ID) && ABV_xfer_flag) {
            video_state_machine();
            ABV_xfer_flag = 0;
        }
#endif
	current_task = what_to_do();

#ifdef FIXEFM
	{
	    static int prev_skip_sectors;
	    if (prev_skip_sectors && !TDM_skip_sectors) {
		/*
		 * We shall start decoding again. Reset video and audio.
		 * We have thrown away a number of sectors!
		 */
		VID_init();
		AUD_init();
	    }
	    prev_skip_sectors = TDM_skip_sectors;
	}
#endif /* FIXEFM */

	if (current_task) DBG_log_task(1, current_task, 0, 0, 0, 0);
	switch (current_task) {
	case 0:
	    TSK_background();
	    break;
	case 1:
	    oh_my(4);
	    TSK_decode_audio();
	    break;
	case 2:
	    oh_my(5);
	    TSK_decode_video();
	    break;
#ifdef KARAOKE
	case 3:
	    oh_my(6);
	    TSK_karaoke();
	    break;
#endif
	case 4:
#ifdef MIC_RECORD
	    if((REC_mode != REC_OFF) && (repeat_a2b == REPEAT_AB_OFF)) {
		check_ABV_xfer();
	    }
#endif
	    TSK_cdda();
	    break;
#ifdef VSCALE
	case 5:
	    /* When vscale is ready, it is not really the new picture is ready,
	       so, the program will scale the old one. In slide show, we have
	       destroied the original picture, it is really bad to see this
	       picture rescaled before the new one coming */
#ifdef ZOOM
	    if ((zoom_level || expect_zoom) &&
		zoom_frame == H_VscaleFrame) resetVscale();
#endif
	    vscale2();
	    break;
#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?