⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 top.c

📁 一个不错的硬盘播放器程序,包含VFD显示程序,红外线遥控程序,硬盘读写程序,及解码程序等.
💻 C
📖 第 1 页 / 共 3 页
字号:
/* Copyright 1997, ESS Technology, Inc.					*/
/* SCCSID @(#)top.c	1.380 2/26/98 */

/*
 * $Log$
 */

#define MAIN

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include "mvd.h"
#include "common.h"
#include "util.h"
#include "debug.h"
#include "buffer.h"
#include "xfer.h"
#include "xport.h"
#include "vp.h"
#include "vcxi.h"
#include "display.h"
#include "huffman.h"
#include "tdm.h"
#include "fsosd.h"
#include "ioport.h"
#include "sysinfo.h"
#include "low.h"
#include "const.h"
#include "dsa.h"
#include "audio.h"
#include "cd.h"
#include "panel.h"
#include "Hm612ndi.h"

#ifdef SUB_PICTURE
#include "spu/spu.h"
#endif
#ifdef PLAY20 
#include "play.h"
#endif
#ifdef MPEG1
#ifdef SVCD
#include "mpegvid.h"
#else
#include "mpeg1vid.h"
#endif
#else
#include "mpeg2vid.h"
#endif
#ifdef AC3
#include "ac3.h"
#else
#include "mpgaudio.h"
#endif
#ifdef KARAOKE
#include "kara.h"
#endif
#ifdef VSCALE
#include "vscale.h"
#endif
#include "ir.h"
#ifdef FRACTINT
#include "fractint.h"
#endif
#ifdef FADE
#include "fade.h"
#endif
#ifdef SPDIF
#include "spdif.h"
#endif
#ifdef ECHO
#include "echo.h"
#endif

#ifdef REAL_CLOCK
#include "realclk.h"
#endif

#if (CUST3 && !CUST71)
#include "custdsa.h"
#endif

#ifdef DVD_VCD
#include "dsa2ide.h"
#include "talk.h"
#endif

#ifdef MZOOM
#include "mzoom.h"
#endif

#include "timedef.h"
#include "constvar.h"
#include "digest.h"	/* have to include, even we do not use digest. */
#include "pts.h"
#include "zoom.h"
#include "dsc.h"
#include "servo.h"
#include "ngame.h"
#include "vcd.h"

#ifdef VCDROM
#include "vcd30.h"
#endif

#ifdef C80
#include "cdconst.h"
#endif

extern int pic_width,pic_height,DISP_screen_on;
extern unsigned char repeat_a2b;

/***************************************************************************
 * Variables local to this module.
 ***************************************************************************/
#ifdef DIGEST_MVD
static int digest_go = 0;
#endif
#ifdef FADE_MVD
static int fade_go = 0;
#endif
int	xfer_mode;
int	b7_already_flushed = 0;

#ifdef VCDROM
unsigned int VCD30_PARAM[16];
unsigned int vcd20_start, vcd20_end, vcd30_cwdloc, vcd30_cwdsz, vcd30_cwdchm;
#endif

#ifdef ZOOM_MVD
static int zoom_go_in = 0;
static int zoom_go_out = 0;
static int zoom_go_left = 0;
static int zoom_go_right = 0;
static int zoom_go_up = 0;
static int zoom_go_down = 0;
#endif

static unsigned int jumpCDtime;

#ifdef C80
extern unsigned char cd_presmodu ;
extern void cd_init(void) ;
extern void cd_main(void) ;
extern void s_scor_by_polling(void) ;
extern void cd_senser(void) ;
extern void cd_exchange(void) ;
#endif

/***************************************************************************
 Various defines.
 ***************************************************************************/

/***************************************************************************
 Debugging.
 ***************************************************************************/
KEYDEBUGVAR(bad_video, 0);
KEYDEBUGVAR(bad_audio, 0);
KEYDEBUGVAR(bad_kara, 0);

#define PRINTF(a)

KEYDEBUGVAR(dram_at_0, 0);
KEYDEBUGVAR(dram_overwrite, 0);

/***************************************************************************
 Local function prototypes.
 ***************************************************************************/

#ifdef CUST6
int GetHC244_sts(void);
void VFD_Getsw(void);
unsigned int HC244_STS;
#endif /* CUST6*/


static void initialization(void);
#ifdef DRAM_GAME
void install_interrupt_vectors(void);
#else
static void install_interrupt_vectors(void); 
#endif
static void wait_huffman_idle(void);
static void TSK_main(void);
static void TSK_decode_audio(void);
static void TSK_decode_video(void);
static void TSK_karaoke(void);
static void TSK_cdda(void);
static void TSK_background(void);
static void TSK_background_high_priority(void);
#ifdef ECHO
static void TSK_echo(void);
#endif
/***************************************************************************
 All low level initialisation.
 ***************************************************************************/
static void initialization()
{
    extern void CUST_init();
    mvd[riface_irqmask] = 0xc000;	/* disable irqs */
    VBV_wrptr = VBV_rdptr = VBV_start = MPEG_VBV_start;
    VBV_size = MPEG_VBV_size;
    PCM_rdptr = PCM_wrptr = PCM_start;
    VBV_end=VBV_start+VBV_size;

#ifdef NEW_EMULATOR
    VCX_init();		/* We are using ROM or emulator? */
#endif

    DISP_screen_on	    = 0;       /* Screen interrupt disabled. */

    LOW_init_rdma();
    LOW_init_buscon();
    LOW_init_dram();
    LOW_init_gateway();
    HUFF_init();
    VP_version();	/* Determine the version number of 3210	*/
    VP_init();
    LOW_init_private_dma();
    install_interrupt_vectors();
    LOW_init_riface();
#ifdef VCDROM
    if (play_clip) {
	mvd[riface_clear_timer2] = 0;       /* clear timer irq */
	mvd[riface_timer2] = timer2_period;
	enable_int(tim2);
    } else
      RISC_start_timer2();
#else
    RISC_start_timer2();
#endif

#ifdef SUB_PICTURE
    SUBPIC_OSD_init();
#else
    OSD_init();
#endif
    PCM_init();
#ifdef KARAOKE
    karaoke_init(&KARAvcd);
#endif 
#ifdef SPDIF
    SPDIF_in_init();
    SPDIF_out_init();
#endif
    LOW_init_audio();
#ifdef SUB_PICTURE
    initial_spu();
#else
    OSD_clear_all();
#endif

#ifdef IR
#ifdef VCDROM
    if (!play_clip)
      IR_init();
    else
      enable_int(debug);
#else
    IR_init();
#endif /* else of VCDROM */
#endif

#ifdef SERVO
    SERVO_init();
#endif

#if (NGAME && PLAY20)
#ifdef SERVO
    NGAME_init(3);
#else
    NGAME_init(2);
#endif
#endif

#ifndef CUST4
#ifdef VCDROM
    if (!play_clip)
      DISP_init();	/* Do this late to minimize garbage */
#else
    DISP_init();	/* Do this late to minimize garbage */
#endif
#endif

#if (PLAYONLY || PLAY20)
    /* Let this be the last one, so AUX pins won't change anymore!! */
    CUST_init();
#endif

#ifdef DSC
    /* 
     * For safety! In case someone changed DSC_SELECT when setting
     * AUX pins, we want to set it back (don't use DSC_getstatus since
     * status may have changed by DSC_init). DSC_toggle uses less code
     * space than DSC_SELECT.
     */
    DSC_toggle();
#endif

    DISP_screen_on	    = 1;
}

/***************************************************************************
 Some hardware, namely the huffman and the VP, can get stuck when there
 is a serious failure somewhere (say because of bad bitstream).
 This routine will reset those hardware. Ideally we should only do this
 when we really need it. Otherwise we should let concealment do its job.
 But then how do we know that we're stuck? The timeout mechanism in
 video and audio decode is one candidate. Should work on this.
 AUD_decode() and VID_decode() should both return an error status.
 An error of -1 means hardware reset is needed. An error of -2 can be
 just ignored.
 ***************************************************************************/
void	hardware_reset(int is_video)
{
    /* Reset the huffman */
    if (is_video) {	/* video error */
	HUFF_reset_state_machine();
    } else {			/* other error */
    	HUFF_reset_output_fifo_and_state();
    }

    /* I don't think the following is done correctly in vp.h */
    VP_cmdq_reset(0);

    /* Reset the VP and reload ucode to DRAM. */
#ifdef VCDROM
    if (VCD_30==1) EVD_VP_init();
    else VP_init();
#else
    VP_init();
#endif

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

/***************************************************************************
 Stop everything.
 ***************************************************************************/
/*
 * This routine can be called at pause to dump ABV and PCM data. When
 * restart, it will search for the next audio sync word.
 *
 * Input:
 *	zap -  0: DRAM to audio DMA is not zapped, so don't touch PCM_rdptr
 *		  and don't set PCM_starved.
 *	       1: DRAM to audio DMA zapped. Reset all pointers to PCM_start.
 */
void system_audio_partial_reset(zap)
int zap;
{
    oh_my(7);

    ABV_stop_filling();
    ABV_stop_draining();
    ABV_wrptr = ABV_rdptr = ABV_start;
    ABV_start_filling();

    /* Reset the PCM pointers */
    if (zap) {
	PCM_rdptr = PCM_start;
#ifdef KARAOKE
	PCM_raw_wrptr = PCM_end - (7*384);
	PCM_fake_data = 1;
	PCM_clear_buffer();
#ifdef SPATIAL
	SPA_wrptr = PCM_wrptr = PCM_raw_rdptr = PCM_start;
#else
	PCM_wrptr = PCM_raw_rdptr = PCM_start;
#endif /* SPATIAL */
#else  /* NOT karaoke */
	PCM_raw_wrptr = PCM_start;
#endif /* KARAOKE */
	PCM_starved = 1;
    } else {
	/*
	 * Partial reset (DRAM to DAC DMA is still going on). Don't touch
	 * PCM_rdptr and don't set PCM_starved.
	 *
	 * 1) No karaoke or spatializer: let PCM_rdptr to catch up 
	 *    PCM_raw_wrptr
	 * 2) With karaoke, no spatializer: dump MPEG raw data, let PCM rdptr
	 *    catch up PCM_wrptr automatically.
	 * 3) With karaoke and spatializer: dump MPEG raw data, dump data
	 *    waiting for spatializer processing, let PCM rdptr catch up 
	 *    SPA_wrptr automatically.
	 */
#ifdef KARAOKE
#ifdef SPATIAL
	PCM_raw_wrptr = PCM_raw_rdptr = PCM_wrptr = SPA_wrptr;
#else
	PCM_raw_wrptr = PCM_raw_rdptr = PCM_wrptr;
#endif /* SPATIAL */
#else
	PCM_raw_wrptr = PCM_rdptr;
#endif /* KARAOKE */
    }

    /* Clear zero buffer in case it is overwritten. */
    PCM_clear_zero_buffer();

#ifdef AC3
    AC3_init();
#endif
#ifdef MUSICAM
    AUD_init();
#endif
}


void	system_reset()
{
    oh_my(0xf);

    /* Stop all ABV/VBV activities */
    VBV_ABV_stop_filling();
    VBV_ABV_stop_draining();

    /* Reset the ABV/VBV pointers */
    VBV_wrptr = VBV_rdptr = VBV_start;
    ABV_wrptr = ABV_rdptr = ABV_start;

    /* Stop all PCM activities */
#ifdef VCDROM
    if (!VCD_30) {
#endif
#ifndef ECHO
    PCM_stop_take_out();
#endif

#ifdef ZERO_BUFFER
    system_audio_partial_reset(0);
#else
    system_audio_partial_reset(1);
#endif
#ifdef VCDROM
    }
#endif
    VID_init();

#ifdef VSCALE    
    if (vcx_scn_vscale != 0x10) {
      resetVscale();
    }
#endif    

#if 0
#ifdef ERROR_CONCEALMENT
    VID_error_timeout = 0;
#endif
#endif

    PTS_xsit = -1;
    audio_is_way_ahead = video_is_way_ahead = 0;

#ifdef MPEG1
    end_of_sequence = b7_already_flushed = 0;
#endif
}

/***************************************************************************
 Start everything.
 ***************************************************************************/
void	system_start()
{
    ABV_start_filling();
    VBV_start_filling();

#ifndef ZERO_BUFFER
#ifndef ECHO
    /*
     * With zero buffer, we only do PCM_start_take_out once, then
     * it will be done continously without stopping.
     */
    PCM_start_take_out();
#endif
#endif
}

/***************************************************************************
 Video decoding task.
 ***************************************************************************/
#define switch_huffman_to_video() do {	\
        mvd[huffdec_control] = 0x40c0;	\
	asm("nop"); asm("nop");		\
        mvd[huffdec_control] = 0x4ac0;	\
	mvd[huffdec_packet_counter] = 0x100; \
} while (0)

#define switch_huffman_to_audio() do {	\
        mvd[huffdec_control] = 0x4000;	\
	asm("nop"); asm("nop");		\
        mvd[huffdec_control] = 0x4a00;	\
} while (0)

static void wait_huffman_idle(void)
{
    volatile int stat2, last_stat2;
    int n = 0;
    VP_cmdq_wait_empty;

    while (1) {
    	stat2 = mvd[huffdec_stat2] & 0x1ffff;
	if (stat2 != last_stat2) n=0; else n++;
    	if (n>10) break;
	last_stat2 = stat2;
    }
}

static void	TSK_decode_video(void)
{
    if (vcx_playaudio_only
#ifdef FIXEFM
	|| TDM_skip_sectors
#endif
    ) {
    	VBV_rdptr = VBV_wrptr;
    	/* Need this since huffdec buscon never finish */
    	if (!VBV_filling) VBV_start_filling();
    } else {
	int error_code;
        DBG_mark_current_time(2);
	switch_huffman_to_video();
#ifndef SVCD
        error_code = VID_decode();
#else
        error_code = (mpeg2) ? VID_decode_MPEG2() : VID_decode();
#endif
    	DBG_check_elapsed(2);
#ifdef MPEG1
	if (error_code 
#ifdef ERROR_CONCEALMENT	  
	    || VID_error_concealment
#endif	 
	) {
	    KEYDEBUGINC(1, bad_video);
	    oh_my(1);
	    hardware_reset(1);
#ifdef ERROR_CONCEALMENT	  
	    VID_copy();
#endif	 
#ifdef VSCALE	    
	    /* 
	     * To fix the checker board problem on playing
	     * scratch disc, we re-page the scaling ucode
	     * again if video error found.
	     */
	    if (vcx_scn_vscale != 0x10) {
	    	initVscale(disp_mem_mode);
	    }
#endif	    
#ifdef ERROR_CONCEALMENT	    
	    if (VID_error_concealment) {
		VID_error_concealment = 0;

⌨️ 快捷键说明

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