top.c
来自「ESS3890+SL原代码(1*16内存)」· C语言 代码 · 共 2,300 行 · 第 1/4 页
C
2,300 行
#ifdef ECHO
case 6:
TSK_echo();
break;
#endif
case 7:
#ifdef ANTI_SHOCK
/* ADPCM encoding task */
TSK_encode_audio();
#endif
break;
#ifdef MZOOM
case 8:
MZM_ip_frame();
break;
#endif
}
if (current_task) DBG_log_task(2, current_task, 0, 0, 0, 0);
/*
* reset the task
*/
current_task = 0;
TSK_background_high_priority();
#ifdef KEYDEBUG
if (dram_at_0 != *((int *)0x12000000)) {
KEYDEBUGINC(1, dram_overwrite);
DBG_console();
}
#endif
} while (1);
}
/* Not every one needs it */
/***************************************************************************
Decode and display an mpeg still.
Side effect: the entire data chain starting from xport is stopped!
***************************************************************************/
int show_mpeg_still(e1e2, data, n)
int e1e2; /* e1e2 = cdda_tv_changed[8] | e1e2[7:0] */
int *data; /* Where data starts */
int n; /* Size of stream in 32-bit words */
{
extern int arodnap;
extern int good_old_days;
extern int picture_type;
#ifdef NOLOGO
arodnap = good_old_days = 0;
#ifdef DEMUX_ON_FLY
DISP_frame = 2;
#endif
/* If we want to save space, we have the option not to include logo */
DISP_paint_screen(COLOR_BLUE, 1, DISP_frame);
#else
int m;
int cdda_tv_changed;
int save[32], matrix_status;
extern int H_CurrFrame;
/* Save quant matrices */
matrix_status = VID_save_q_matrices(save);
arodnap = good_old_days = 0;
assert(n <= VBV_size);
cdda_tv_changed = e1e2 & 0xf00;
if (cdda_tv_changed) {
/* don't touch the ABV during CDDA TV-mode change..
* i.e. no system_reset()
*/
VBV_reset();
} else
#ifdef MP3
if (STREAM_type == MP3_ID) {
/* Fake it so that we'll do video decoding of still picture */
STREAM_type = 0;
system_reset();
STREAM_type = MP3_ID;
} else
#endif
{
system_reset();
}
/* Move the data to the VBV.
Force data size to be integer multiples of VBV_read. */
sram_to_dram(VBV_start, data, n);
m = n % VBV_read;
if (m) {
int *p = (int *)dram(VBV_start + n);
while (m++ < VBV_read) {
*p++ = 0; n++;
}
}
VBV_wrptr_advance(n);
PRINTF(("LOGO (%d) now in DRAM at 0x%x.\n", n, dram(VBV_start)));
/* Start draining the VBV. We set VBV_filling to 1 to fool
hufdecv_xfer_end into not starting a xportv_xfer. */
VBV_start_draining();
VBV_filling = 1;
#if defined(MP3_LOGO) || defined(DEMUX_ON_FLY)
show_logo_pro = 1;
#endif
picture_type = e1e2 & 0xff;
/* The real decoding loop */
VID_decoding_in_progress = 1;
while (VID_decoding_in_progress) {
#ifdef ECHO
MIC_service();
#endif
VID_decode();
}
#if defined(MP3_LOGO) || defined(DEMUX_ON_FLY)
if(show_logo_pro != 0) {
show_logo_pro = 0;
DISP_frame = 2;
} else
#endif
{
#ifdef VSCALE
/* Do vertical scaling if necessary */
if ((vcx_scn_vscale != 0x10) &&
(vcx_user_video_stream != 0xe2)){
H_VscaleFrame = H_CurrFrame;
initVscale_Pointer();
VscaleStart = 1;
VscaleLastFrame = 0;
while (VscaleStart) {
#ifdef ECHO
MIC_service();
#endif
vscale2();
}
DISP_frame = 2;
} else DISP_frame = H_CurrFrame;
#else
DISP_frame = H_CurrFrame;
#endif
DISP_count = 0;
}
#ifdef PLAY20
/* clear unused display frames..already done in av_play_motion() */
showingLogo = pic_width;
#endif
if (cdda_tv_changed) {
/* don't reset the ABV during CDDA TV-mode change */
VBV_stop_draining();
VBV_reset();
} else {
system_reset();
/* Restore quant matrices */
VID_restore_q_matrices(matrix_status, save);
}
picture_type = 0xe0; /* also reset picture_type*/
#endif /* NOLOGO */
}
/*#define STACK_CHECK /* enable to check stack usage */
#ifdef STACK_CHECK
/* calculate these from information after compiling..
* Then recompile with the correct stack info before downloading,
* or else this may overwrite data area!!
*
* NOTE: DATA_END = <stack start> - <stack size>
*/
#define DATA_END (0x4000 - 0xb30)/4 /* DWORD address */
#define HALF_STACK_SIZE (0xb30/8) /* in Dword */
#define INIT_DATA 0xaaaaaaaa
#define FILL_STACK() \
{ \
int i,n = HALF_STACK_SIZE,*dstp = (int *)dram(DATA_END); \
while(n--) { \
*dstp++ = INIT_DATA; \
for (i = 0; i < 32; i++) \
asm("nop"); \
} \
}
#else
#define FILL_STACK()
#endif /* STACK_CHECK */
/***************************************************************************
The main entry point.
***************************************************************************/
main()
{
/* ******** RISC and register setups ******** */
register int psw_shadow = 0xc3;
asm volatile("movtos %0,psw" : :"r" (psw_shadow) );
mvd = (int *)OMNI_BASE;
FILL_STACK(); /* used to check stack usage if defined */
#ifdef DSC
DSC_getstatus();
#endif
Init_const();
init_definition();
initialization();
DBG_allocate_trace_buffer();
DBG_my_allocate_trace_buffer();
TSK_main();
}
#ifdef MP3
void MP3_start(void)
{
#if (defined(JPEG_DEC) && defined(GSCALE))
{
DISP_Info *dip;
dip = DISP_info + disp_frame;
jpg_scale_width = (dip->wY)<<2;
}
#endif
/* ABV_stop_filling() & ABV_stop_draining()..
* already in system_audio_partial_reset().
*/
/* to avoid MP3_init() been called in system_audio_partial_reset() */
MPG_layer = 0;
system_audio_partial_reset(1);
#ifdef MP3CDG
if (MP3CDG_started) {
ABV_start = MP3CDG_ABV_start;
ABV_size = mp3cdg_abv_size;
} else
#endif
{
ABV_start = MP3_ABV_start;
ABV_size = ((init_disp_share() - ABV_start - MP3_ID3_size) /
ABV_CHUNK) * ABV_CHUNK;
}
ABV_end = ABV_start + ABV_size;
#ifdef ANTI_SHOCK
ABV_gdptr = ABV_start;
#endif
/* We are decompressing MP3's text and data to display(B&P)..
* make sure init_disp_share() is done first!
*/
#ifdef ECHO
MIC_service();
#endif
MP3_download_code();
#ifdef ECHO
MIC_service();
#endif
MP3_low_init();
#ifdef TRACE_MP3_AUDIOBREAK
MP3_is_decoding = 1;
MP3_is_takeout = 0;
#endif
}
#endif
#ifdef WMA_DEC
void WMA_start(void)
{
#if (defined(JPEG_DEC) && defined(GSCALE))
DISP_Info *dip;
dip = DISP_info + disp_frame;
jpg_scale_width = (dip->wY)<<2;
#endif
/* ABV_stop_filling() & ABV_stop_draining()..
* already in system_audio_partial_reset().
*/
system_audio_partial_reset(1);
#ifndef WMA_DEMO
flush_thy_audio=0;
#endif
ABV_start = WMA_ABV_start;
ABV_size = ((init_disp_share() - WMA_ABV_start)/ABV_CHUNK)*ABV_CHUNK;
ABV_end = ABV_start + ABV_size;
#ifdef ANTI_SHOCK
ABV_gdptr = ABV_start;
#endif
ABV_wrptr = ABV_rdptr = ABV_start;
#ifdef XSEG3_ON_FLY
if (vcx_xseg_loaded != XSEG3_CODE) {
/* We are decompressing WMA's text and data to display(B&P)..
* make sure init_disp_share() is done first!
*/
Decompress(xtra_s3_compress_data_start,
(WMA_globals_start<<2), XSEG3_DATA);
Decompress(xtra_s3_compress_text_start,
dram_cached(WMA_CODE_start), XSEG3_CODE);
}
#endif /* XSEG3_ON_FLY */
#ifdef ECHO
MIX_init();
#endif
WMA_init();
HUFF_init();
hardware_reset(1);
vcx_playaudio_only = 1;
VP_need_to_restore_ucode |=
(VP_RESTORE_MPG_UCODE|VP_RESTORE_MP3_UCODE|VP_RESTORE_JPG_UCODE|\
VP_RESTORE_GSL_UCODE|VP_RESTORE_GAM_UCODE|VP_RESTORE_EQU_UCODE);
}
#endif
#ifdef JPEG_DEC
#ifdef JPEG_ROTATE
extern int JPEG_ReDecoding;
#endif
void JPG_start(int jpg_type)
{
if (!jpg_type) return;
VBV_stop_filling();
VBV_ABV_stop_draining();
is_jpeg = jpg_type; /* 1: JPEG 2: MJPEG */
VBV_ABV_default();
VBV_reset();
flush_done = 1;
flush_thy_video = 0;
if (jpg_type != 2) vcx_playvideo_only = 1;
#ifdef GSCALE
DISP_change_resolution(pic_width, 2*vcx_scn_height);
#else
DISP_change_resolution(720, 2*vcx_scn_height);
#endif
#ifdef JPEG_ROTATE
if(JPEG_ReDecoding) OUTOSD(1, "PROCESSING", "PROCESSING", 2);
#endif
DISP_frame = 2;
DISP_count = 0;
VP_need_to_restore_ucode |=
(VP_RESTORE_GSL_UCODE|VP_RESTORE_JPG_UCODE);
}
#endif
#ifdef AVI_DEC
void AVI_start(void)
{
ABV_stop_filling();
ABV_stop_draining();
system_audio_partial_reset(1);
ABV_start = AVI_ABV_start;
ABV_size = AVI_ABV_size;
ABV_end = ABV_start + ABV_size;
ABV_wrptr = ABV_rdptr = ABV_start;
ABV_byte_start = dram(ABV_start);
ABV_byte_end = dram(ABV_end);
ABV_byte_size = (ABV_size << 2);
ABV_byte_rdptr = ABV_byte_wrptr = ABV_byte_start;
WAV_wrptr = WAV_rdptr = WAV_start;
WAV_byte_start = dram(WAV_start);
WAV_byte_end = dram(WAV_end);
WAV_byte_size = (WAV_size << 2);
WAV_byte_rdptr = WAV_byte_wrptr = WAV_byte_start;
JPG_start(2);
VBV_byte_start = dram(VBV_start);
VBV_byte_end = dram(VBV_end);
VBV_byte_size = (VBV_size << 2);
VBV_byte_rdptr = VBV_byte_wrptr = VBV_byte_start;
ABV_start_filling();
AVI_init();
}
#endif
/***************************************************************************
Misc interrupt handling.
***************************************************************************/
extern void trap0;
static int *trapptr0 = &trap0;
#ifndef DRAM_GAME
static
#endif
void install_interrupt_vectors()
{
int *a, *b, i;
#ifdef MKROM
b = (int*)((int)trapptr0<<2);
#else
b = (int*)((int)trapptr0);
#endif
/*
* The DWORD at 0x18 is used for resume!!
* The DWORD at 0x1c is used for real-time clock!!
*
* Don't read 0x10 to 0x1f, they meant to be noncachable.
*/
for (a = (int*)0, i = 0; i < 4; i++) *a++ = *b++;
}
#if (defined(MP3) || defined(WMA_DEC))
int init_disp_share(void)
{
if (!(vcx_xseg_loaded & (XSEG3_CODE|XSEG4_CODE))) {
/* MP3/WMA use B & P..I for display */
DISP_change_resolution(352, 288); /* PAL worse case */
pic_width = 352;
pic_height = 288;
DISP_frame = 0; /* I-frame */
DISP_count = 0;
DISP_paint_screen(NAV_MENU_BKGD, 0, 0);
}
#if defined(ANTI_SHOCK) || !defined(MIC_RECORD)
/* For ANTI_SHOCK, we are using SHARE for additional ABV..
* i.e. no MIC_RECORD for MP3 or WMA, if ANTI_SHOCK is enabled!
*/
return (SHARE_end);
#else
return (DISP_end);
#endif
}
#endif /* MP3 || WMA */
/* Move this out of display.c so that FAE's can
* enable/disable LTOC_TV_CHANGE in the field.
*/
void DISP_TV_service(void)
{
if ((vcx_scn_height != DISP_scn_height) || do_blank) {
/*
* Only start the mode changing process if we are showing
* blank screen to minimize garbage on screen.
*/
if (!do_blank) {
done_blank = 0;
do_blank = 1;
} else {
if ((!VID_decoding_in_progress ||
vcx_fast_forward || vcx_playaudio_only) &&
done_blank) {
DISP_change_TV();
do_blank = 0;
#ifdef PLAY20
#ifdef LTOC_TV_CHANGE
/* if we're in ltoc loop..redecode logo */
if (!initCD_done) show_still_pic();
else
#endif
tv_changed = 1; /* for reloading stills */
#endif /* PLAY20 */
}
}
}
}
/***************************************************************************
PTS processing.
For MPEG 1 We store PTS in 32 bits unsigned, measured in 45khz.
One NTSC frame is 3003/2. For MPEG 2 PTS is measured in 27Mhz, and one
NTSC frame is 900900. One PAL frame is 1800 for MPEG1 and 1080000 for MPEG2.
We consider a difference of 10 frames (around
330ms) to be out-of-sync. If the difference is too big it could be
wrap-around. PCM buffer delay is based on all data in PCM, both raw
and processed.
***************************************************************************/
#define WAY_OFF 10*1800 /* Use PAL number */
#define REORDER_DELAY 3*1800 /* Assume M=3 */
/* DEBUGVAR(pts_diff, 0); */
#define PTS_units_per_256_VBV_dwords 321 /* 256*32*45000/1150000 */
#define PTS_units_per_256_ABV_dwords 1646 /* 256*32*45000/224000 */
void process_pts(void)
{
int d;
int space, buffer_delay;
#ifdef MIC_RECORD
int e, abv_fullness, pcm_fullness;
extern uint REC_PTS_aud;
#endif
if (!vcx_ignore_pts) {
PCM_update_space(space);
#ifdef MIC_RECORD
PCM_update_occupancy(pcm_fullness);
ABV_update_occupancy(abv_fullness);
/* We don't really know where in the packet does the PTS refer */
abv_fullness -= 256; if (abv_fullness<0) abv_fullness = 0;
e = (261 * pcm_fullness +
PTS_units_per_256_ABV_dwords * abv_fullness) >> 8;
#endif
buffer_delay = ((PCM_size-space)*PTS_units_per_256_audio_samples)>>8;
d = PTS_aud - PTS_vid + REORDER_DELAY;
d -= buffer_delay;
d += (VBV_fullness * PTS_units_per_256_VBV_dwords -
ABV_fullness * PTS_units_per_256_ABV_dwords)>>8;
audio_is_way_ahead = (d > WAY_OFF) && (d < 100*WAY_OFF);
video_is_way_ahead = (d < -WAY_OFF) && (d > -100*WAY_OFF);
/* DEBUGASSIGN(pts_diff, d); */
DEBUGINC(audio_is_way_ahead, audio_ahead);
DEBUGINC(video_is_way_ahead, video_ahead);
PRINTF(("A %d, V %d, d %d\n",PTS_aud,PTS_vid,d));
#ifdef MIC_RECORD
REC_PTS_aud = PTS_aud - e;
#endif
}
PTS_xsit = 0;
}
#ifdef MP3
void MP3_download_code()
{
#ifdef XSEG4_ON_FLY
if (vcx_xseg_loaded != XSEG4_CODE) {
#ifdef COMPRESS_MP3_UCODE
/* Compressed ucode.."-8" adjustment for Decompress() */
Decompress((int)(T_GROUP_ucode_data-8),
dram_cached(MP3_UCODE_start), 0);
#endif
Decompress(xtra_s4_compress_data_start,
dram_cached(MP3_globals_start), XSEG4_DATA);
Decompress(xtra_s4_compress_text_start,
dram_cached(MP3_CODE_start), XSEG4_CODE);
}
#endif /* XSEG4_ON_FLY */
}
void MP3_low_init()
{
ABV_byte_start = dram(ABV_start);
ABV_byte_end = dram(ABV_end);
ABV_byte_size = (ABV_size << 2);
ABV_byte_rdptr = ABV_byte_start;
ABV_byte_wrptr = ABV_byte_start;
ABV_wrptr = ABV_rdptr = ABV_start;
#ifdef ECHO
MIX_init();
#endif
MPG_layer = 3; /* default */
MP3_init();
HUFF_init();
hardware_reset(1);
vcx_playaudio_only = 1;
VP_need_to_restore_ucode |= VP_RESTORE_MP3_UCODE;
}
#endif /*MP3*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?