top.c
来自「ESS3890+SL原代码(1*16内存)」· C语言 代码 · 共 2,300 行 · 第 1/4 页
C
2,300 行
/* Copyright 1997, ESS Technology, Inc. */
/* SCCSID @(#)top.c 4.74.1.36 03/09/05 */
/*
* $Log$
*/
#define MAIN
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include "vcxi.h"
#include "vp.h"
#include "memmap.h"
#include "util.h"
#include "debug.h"
#include "buffer.h"
#include "xfer.h"
#include "xport.h"
#include "filesys.h"
#include "display.h"
#include "huffman.h"
#include "tdm.h"
#include "eq.h"
#include "low.h"
#include "const.h"
#include "dsa.h"
#include "audio.h"
#include "cd.h"
#include "panel.h"
#include "mpeg1vid.h"
#include "mpgaudio.h"
#include "nav_menu.h"
#include "dummy.h"
#ifdef SCR_SAVER
#include "scrsaver.h"
#endif
#ifdef TWO_FIELDS_OSD
#include "cg.h"
#else
#include "fsosd.h"
#endif
#ifdef PLAY20
#include "play.h"
#include "av_play.h"
#endif
#ifdef HOST_SLAVE
#include "slave.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 ECHO
#include "echo.h"
#endif
#ifdef REAL_CLOCK
#include "realclk.h"
#endif
#ifdef MZOOM
#include "mzoom.h"
#endif
#include "timedef.h"
#include "digest.h" /* have to include, even we do not use digest. */
#include "pts.h"
#include "zoom.h"
#include "servo.h"
#include "vcd.h"
#include "recorder.h" /* MIC_RECORD */
#ifdef GDTSERVO
#include "servogdt.h"
#endif
#ifdef MP3
#include "mp3.h"
#ifdef ID3
#include "id3.h"
#endif
#endif MP3
#if (defined CDG || defined CD_TEXT)
#include "cd_text.h"
#ifdef CDG
#include "cdg.h"
#endif
#endif
#ifdef FLESHTONE
#include "fshtone.h"
#endif
#if (defined INES_CD || defined VGB_CD)
#include "game.h"
#endif
#ifdef AVI_DEC
#include "avi.h"
#endif
#ifdef GAMMA
extern int gamma_index;
#endif
extern int pic_width,pic_height,DISP_screen_on;
extern unsigned char repeat_a2b;
extern int show_logo_pro;
/***************************************************************************
* Variables local to this module.
***************************************************************************/
int xfer_mode;
int b7_already_flushed = 0;
static unsigned int jumpCDtime;
/***************************************************************************
Various defines.
***************************************************************************/
/***************************************************************************
Debugging.
***************************************************************************/
#if 0
int bpt;
#define BREAKPOINT(x) {bpt=x;while(bpt) VCX_service();}
#else
#define BREAKPOINT(x)
#endif
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.
***************************************************************************/
static void initialization(void);
static void init_definition(void);
#ifdef DRAM_GAME
void install_interrupt_vectors(void);
#else
static void install_interrupt_vectors(void);
#endif
static void TSK_main(void);
static void TSK_decode_video(void);
static void TSK_karaoke(void);
static void TSK_cdda(void);
static void PCM_volume_adjust(int, int);
void TSK_background(void);
static void TSK_background_high_priority(void);
#ifdef ECHO
static void TSK_echo(void);
#endif
#ifdef ANTI_SHOCK
static void TSK_encode_audio(void);
static void ITU_decode(void);
#endif
/***************************************************************************
Global function prototypes.
***************************************************************************/
void process_pts(void);
void TSK_decode_audio(void);
#ifdef MP3
void MP3_start(void);
#endif
#ifdef JPEG_DEC
void flush_video_if_possible(void);
void JPG_start(int);
#endif
#ifdef WMA_DEC
void WMA_start(void);
#endif
#ifdef AVI_DEC
void AVI_start(void);
#endif
#ifdef MP3
void MP3_download_code();
void MP3_low_init();
#endif
/***************************************************************************
All low level initialisation.
***************************************************************************/
static void initialization()
{
extern void CUST_init();
mvd[riface_irqmask] = 0xc000; /* disable irqs */
VBV_ABV_default();
VBV_wrptr = VBV_rdptr = VBV_start;
PCM_rdptr = PCM_wrptr = PCM_start;
#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 */
#ifdef MP3
#ifdef ENABLE_MP3
MP3_enabled = 1;
#endif
#endif
#ifdef FLESHTONE
Fleshtone_Init();
#endif
#ifdef COMPRESS_ALL_UCODE
/* Compressed ucode.."-8" adjustment for Decompress() */
Decompress((int)(T_GROUP_ucode_data-8), dram_cached(UCODE_start), 0);
#endif
VP_init(0);
LOW_init_private_dma();
install_interrupt_vectors();
LOW_init_riface();
RISC_start_timer2();
#ifdef CD7II
RISC_start_timer1();
#endif
#ifdef TWO_FIELDS_OSD
CG_set_scr(CG_FULL_SCR);
ICON_init();
#else
OSD_init();
#endif /* TWO_FIELDS_OSD */
PCM_init();
#ifdef KARAOKE
karaoke_init(&KARAvcd);
#endif
LOW_init_audio();
CLEARALLOSD();
#ifdef IR
IR_init();
#endif
DISP_init(); /* Do this late to minimize garbage */
/* Do servo related initialization after "system" initializations
* to decrease problems with timing delays in servo initialization..
* especially when customers modify the servo init code later on.
*/
#if (defined CDG || defined CD_TEXT)
#ifndef USE_SERVO_INT
DSC_init_subcode(0, DSC_RISING_EDGE);
#endif
#endif
#ifdef DSC_ENABLE_C2PO
DSC_init_c2po(1, DSC_RISING_EDGE);
#endif
#ifdef GDTSERVO
DSC_init_servoint(1, DSC_RISING_EDGE);
SERVO_rest();
#endif
#if ((SERVO || TCSERVO ) && !CD7II)
SERVO_init();
#ifdef SERVO
#ifdef ESS3721
Ess3721_reset_start();
Ess3721_reset_end();
#else
SERVO_DSP_init(); /* not for Toshiba DSP */
#endif
#endif /* SERVO */
#endif
#ifdef CD7II
SERVO_host_init();
#endif
/* Let this be the last one, so AUX pins won't change anymore!! */
CUST_init();
#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;
}
void init_definition(void)
{
#ifdef ANTI_SHOCK
gbl_define_flg |= 0x01;
#ifndef DSC_ENABLE_C2PO
/* ANTI_SHOCK requires C2PO enabled boards,i.e.USE_C2PO_GRP in make.sh */
ERROR - ANTI_SHOCK: please verify that your board can support C2PO!
#endif
#endif /* ANTI_SHOCK */
#ifdef MIC_RECORD
gbl_define_flg |= 0x02;
#endif
#ifdef SCLK_USE_AUX
gbl_define_flg |= 0x04;
#endif
#ifdef FOK_USE_SENS
gbl_define_flg |= 0x08;
#endif
#ifdef DSC_ENABLE_S0S1
gbl_define_flg |= 0x10;
#endif
#ifdef DSC_ENABLE_C2PO
gbl_define_flg |= 0x20;
#endif
#if defined(CDG) || defined(CD_TEXT)
gbl_define_flg |= 0x40;
#endif /* CDG || CD_TEXT */
}
/***************************************************************************
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. */
VP_init((STREAM_type==MP3_ID));
/* 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();
#ifdef ANTI_SHOCK
AS_ABV_wrptr = AS_ABV_rdptr = AS_ABV_start;
ABV_gdptr = ABV_start;
#endif
ABV_wrptr = ABV_rdptr = ABV_start;
#if (defined(MP3) || defined(AVI_DEC))
ABV_byte_rdptr = ABV_byte_start;
ABV_byte_wrptr = ABV_byte_start;
#endif
ABV_start_filling();
/* Reset the PCM pointers */
if (zap) {
PCM_rdptr = PCM_start;
#ifdef KARAOKE
#ifndef WMA_DEC
PCM_raw_wrptr = PCM_end - (7*384);
#else
PCM_raw_wrptr = PCM_end - (20*384);
#endif
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 MUSICAM
#ifdef MP3
if ((STREAM_type == MP3_ID)
&& MPG_layer) {
MP3_init();
} else
#endif
#ifdef WMA_DEC
if (STREAM_type == WMA_ID) {
return;
} else
#endif
#ifdef AVI_DEC
if (STREAM_type == AVI_ID) {
return;
} else
#endif
{
#ifdef GAMEBOY
if (gmby_name_id == 0)
#endif
AUD_init();
#ifdef PRE_EMPHASIS
vcx_deemphasis_init = vcx_deemphasis;
#endif PRE_EMPHASIS
}
#endif MUSICAM
}
void system_reset()
{
oh_my(0xf);
#ifdef JPEG_DEC
if (is_jpeg) {
HUFF_init();
JPG_reset();
}
#endif
/* Stop all ABV/VBV activities */
VBV_ABV_stop_filling();
VBV_ABV_stop_draining();
/* Reset the ABV/VBV pointers */
#ifdef ANTI_SHOCK
AS_ABV_wrptr = AS_ABV_rdptr = AS_ABV_start;
ABV_gdptr = ABV_start;
#endif
VBV_wrptr = VBV_rdptr = VBV_start;
#ifdef DATA_CD
if ( ((STREAM_type == MP3_ID) && MPG_layer)
#ifdef WMA_DEC
|| (STREAM_type == WMA_ID)
#endif
#ifdef AVI_DEC
|| (STREAM_type == AVI_ID)
#endif
) {
ABV_wrptr = ABV_rdptr = ABV_start;
} else {
ABV_wrptr = ABV_rdptr = VCD_ABV_start;
#ifndef ANTI_SHOCK
/* for ESP, CDDA ABV takes extra space from VBV */
ABV_end = VCD_ABV_end;
ABV_size = VCD_ABV_size;
#endif
}
#else
ABV_wrptr = ABV_rdptr = ABV_start;
#endif
TDM_needs_flush = 0;
/* Stop all PCM activities */
#ifndef ECHO
PCM_stop_take_out();
#endif
#ifdef ZERO_BUFFER
system_audio_partial_reset(0);
#else
system_audio_partial_reset(1);
#endif
VID_init();
#ifdef VSCALE
if (vcx_scn_vscale != 0x10) {
resetVscale();
}
#endif
#if 0
#ifdef ERROR_CONCEALMENT
VID_error_timeout = 0;
#endif
#endif
#ifdef ERROR_CONCEALMENT
concealment_mode = (error_concealment_mode == 1) ? JERKY : BLOCKY;
last_check_time = 0;
last_check_frame = 0;
#if 0 /* don't change..this is customized in sysinfo.h */
EC_Index = 4;
#endif
#endif
PTS_xsit = -1;
audio_is_way_ahead = video_is_way_ahead = 0;
end_of_sequence = b7_already_flushed = 0;
#ifdef MP3
if ((STREAM_type == MP3_ID) && MPG_layer) MP3_start();
#endif
#ifdef WMA_DEC
if (STREAM_type == WMA_ID) WMA_start();
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?