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

📄 debug.c

📁 一个不错的硬盘播放器程序,包含VFD显示程序,红外线遥控程序,硬盘读写程序,及解码程序等.
💻 C
📖 第 1 页 / 共 3 页
字号:
}/***************************************************************************** Write dpcm. *****************************************************************************/static int proc_wdpcm(){    int	  sadr;    char  keyin[40];    int	  where, n;    printf("DRAM offset(x), VP address in shorts(d), n in dwords(d): ");    gets(keyin); sscanf(keyin,"%x,%d,%d",&where,&sadr,&n);    dp_dm_write(0, where, n, sadr);    return(0);}/***************************************************************************** Dump dp. *****************************************************************************/static int proc_ddp(){	dp_dm_dump(1);	return(0);}/***************************************************************************** Dump dpcm. *****************************************************************************/static int proc_ddpcm(){	dp_dm_dump(0);	return(0);}/***************************************************************************** Dump reference memory. *****************************************************************************/static int proc_dref(){	ref_dump();	return(0);}#define readdp(a)        mvd[buscon_cmdque_vpcbuswr] =  0x5800 | (a)#define readdpcm(a)      mvd[buscon_cmdque_vpcbuswr] =  0x5000 | (a)#define sendendio() do { \    mvd[buscon_cmdque_vpstatwait] = 0x0400; \    mvd[buscon_cmdque_vpstatwait] = 0x8400; } while (0)/****************************************************************************** Dump reference memory, 16x16 block. ******************************************************************************/static void ref_dump(void){    int	 xadr, yadr, width, base;    char keyin[40];    printf("Enter x(d), y(d), width(d) in bytes, base_linear_address(x):\n");    gets(keyin);    sscanf(keyin,"%d %d %d %x",&xadr,&yadr,&width,&base);    while(1) {        int  i, j, k;	printf("       %8d %8d %8d %8d\n",xadr,xadr+4,xadr+8,xadr+16);	printf("---------------------------------------\n");	j = yadr;	for (i=0 ; i<16 ; i++) {	    int *ptemp = (int *)(base + ((yadr+i)*width) + xadr + 0x12000000);	    printf("%4d : ",j++);	    for (k=0; k<4; k++) printf("%08x ", *ptemp++);	    printf("\n");	}	printf("---more or 'q'----");	gets(keyin);	if(keyin[0]=='q') return;	yadr += 16;    }}/****************************************************************************** Load ucode from dram to VP. ******************************************************************************/static int proc_load_ucode(){    int	  sadr, fp;    char  keyin[40];    int	  where, n;    char  fname[20];    printf("Filname: "); scanf("%s", fname);    printf("ucode RAM addr: ");    gets(keyin); gets(keyin); sadr = AsciiHIToDw(keyin);    printf("Warning: I'm overwriting the U component of your B frame!\n");    where = DISP_info[2].startU;    n = DBG_load_memory((char *)dram(where), -1, 0, -1, fname)/4;    printf("addr = 0x%x, n = %d long words.\n", sadr, n);#if 0    load_vp(where, sadr, n);#endif    return(0);}/****************************************************************************** Run a piece of ucode. ******************************************************************************/static int proc_run_ucode(){    char  keyin[40];    int	  sadr;    printf("Entry point: ");    gets(keyin); sadr = AsciiHIToDw(keyin);    printf("addr 0x%x\n", sadr);    VP_ucode(NCMDQ_VP_ucode, sadr);    return(0);}/****************************************************************************** Load to dp and dpcm. ******************************************************************************/static void dp_dm_load(int write_dp){    int	  sadr;    char  keyin[40];    int	  where, n, dx, dy;    char  fname[20];    printf("Filname: "); scanf("%s", fname);    printf("DP/DPCM addr in shorts: ");    gets(keyin); gets(keyin); sadr = AsciiHIToDw(keyin);    printf("Warning: I'm overwriting the U component of your B frame!\n");    where = DISP_info[2].startU;    n = DBG_load_memory((char *)dram(where), -1, 0, -1, fname)/4;    printf("addr = 0x%x, n = %d long words.\n", sadr, n);    dp_dm_write(write_dp, where, n, sadr);}/****************************************************************************** Write to dp and dpcm. ******************************************************************************/static void dp_dm_write(int write_dp, int where, int n, int sadr){    int	cmd, dx, dy;    dy = n>>8;    dx = n-(dy<<8);    PRINTF(("dram=%d, dp/dpcm=0x%x, dx=%d, dy=%d\n",where,sadr,dx,dy));    cmd = (write_dp) ? VPCMD_W_DP : VPCMD_W_DPCM;    if (dy) {	VP_xfer(NCMDQ_VP_xfer, cmd, sadr, VPDMA_USEDX, where, 256, dy);	sadr += dy<<9;	where += dy<<8;    }    if (dx) VP_xfer(NCMDQ_VP_xfer, cmd, sadr, VPDMA_USEDX, where, dx, 1);}/****************************************************************************** Dump dp and dpcm. Dump to DISP_info[2].startU for now. ******************************************************************************/static void dp_dm_dump(int dump_dp){    int	  sadr, i;    char  keyin[40];    int	  where, cmd;    printf("Warning: I'm overwriting the U component of your B frame!\n");    printf("DP/DPCM addr in shorts: ");    gets(keyin); sadr = AsciiHIToDw(keyin);    where = DISP_info[2].startU;    cmd = (dump_dp) ? VPCMD_R_DP : VPCMD_R_DPCM;    while(1)    {	printf("------------------------------------ ");    	VP_xfer(NCMDQ_VP_xfer, cmd, sadr, 0, where, 64, 1);	printf("At %04x:\n", sadr);	DBG_print_short(128, (ushort *)dram(where));	printf("----more or 'q'----");	gets(keyin);	if(keyin[0]=='q') return;	sadr += 128;    }}/****************************************************************************** Save dp and dpcm. Dump to DISP_info[2].startU for now. ******************************************************************************/static void dp_dm_save(int save_dp){    int	  sadr, fp;    char  keyin[40];    int	  where, n;    char  fname[20];    int	  cmd, dx, dy;    printf("Filname: "); scanf("%s", fname);    printf("DP/DPCM addr in shorts: ");    gets(keyin); gets(keyin); sadr = AsciiHIToDw(keyin);    printf("No of 32 bit words to save: ");    gets(keyin); n = AsciiHIToDw(keyin);    printf("Warning: I'm overwriting the U component of your B frame!\n");    where = DISP_info[2].startU;    dy = n>>8;    dx = n-(dy<<8);    printf("dram=%d, dp/dpcm=0x%x, dx=%d, dy=%d\n",where,sadr,dx,dy);    cmd = (save_dp) ? VPCMD_R_DP : VPCMD_R_DPCM;    if (dy) {	VP_xfer(NCMDQ_VP_xfer, cmd, sadr, VPDMA_USEDX, where, 256, dy);	sadr += dy<<9;	where += dy<<8;    }    if (dx) VP_xfer(NCMDQ_VP_xfer, cmd, sadr, VPDMA_USEDX, where, dx, 1);    fp = DBG_dump_memory((char *)dram(where), n<<2, -1, fname);     if (fp != -1) close(fp);}/****************************************************************************** Read the vp. ******************************************************************************/static int rdrlatchport(void){    int tdata;    int tdata2;    while (!(mvd[buscon_cmdque_status] & 0x8)) {    /* wait for bcdw */	tdata2 = mvd[buscon_cmdque_test] & 0x7ffff;	tdata2 = mvd[buscon_cmdque_numentries] & 0x1f;	tdata2 = mvd[buscon_dma_cntl] & 0x7fff;    }    tdata = mvd[buscon_cmdque_rdrlatchh];    tdata <<= 16;    tdata |= mvd[buscon_cmdque_rdrlatchl] & 0xffffL;    return(tdata);}static int peekvp(void){    mvd[buscon_cmdque_vprd] = 0x0000;     /* read vp */    return(rdrlatchport()); 	/* get the data */}/************************************************************************** Nicely print a block of memory as unsigned ints. **************************************************************************/void DBG_print_int(int n, int *x){    int i, j, y;    i = 0;    for (j=0; j<n; j++) {	if (i==0) {	   y = (int)x;	   if (y>=0x12000000) y -= 0x12000000;	   printf("%06x: ",y);	}        if (i==7) {           printf("%08x\n",*x++);           i = 0;        } else {           printf("%08x ",*x++);           i++;        }    }    }/************************************************************************** Nicely print a block of memory as unsigned shorts. **************************************************************************/void DBG_print_short(int n, unsigned short *x){    int i, j;    i = 0;    for (j=0; j<n; j++) {        if (i==15) {           printf("%04x\n",x[j]);           i = 0;        } else {           printf("%04x ",x[j]);           i++;        }    }    }/************************************************************************** Read a block of memory from a file. If (n<0) read the entire file and return the length. Otherwise read n bytes and return the file handle. **************************************************************************/int  DBG_load_memory(p, n, x, fp, s)char *p;	/* starting byte address */int  n;		/* number of bytes to read */int  x;		/* offset from start of file */int  fp;	/* file handle */char *s;	/* name of file to read from */{    if (fp==-1) {    	fp = open(s, O_BINARY | O_RDONLY );    	if (fp==-1) {    	    printf("Can't open %s\n", s);	    return(-1);    	}	if (x>0) {	    if (lseek(fp, x, 0) != x) {    	        printf("Seek %d failed for %s\n", x, s);	        return(-1);	    }	}    }    if (n<0) {	n = 0;    	while (read(fp, p, 4) == 4) {	    p += 4; n += 4;	}	close(fp);	return(n);    }    while (n >= 16384) {    	if (read(fp, p, 16384) == 0) {	    printf("Error reading from %s\n", s);	    close(fp);	    return(-1);	}	p += 16384;	n -= 16384;    }    if (n) read(fp, p, n);    return(fp);}/************************************************************************** Dump a block of memory to a file. **************************************************************************/int  DBG_dump_memory(p, n, fp, s)char *p;	/* starting byte address */int  n;		/* number of bytes to dump */int  fp;	/* file handle */char *s;	/* name of file to dump to */{    if (fp==-1) {    	fp = open(s, O_BINARY | O_WRONLY | O_CREAT | O_TRUNC);    	if (fp==-1) {    	    printf("Can't open %s\n", s);	    return(-1);    	}    }    while (n >= 16384) {    	if (write(fp, p, 16384) == 0) {	    printf("Error writing to %s\n", s);	    close(fp);	    return(-1);	}	p += 16384;	n -= 16384;    }    if (n) write(fp, p, n);    return(fp);}/***************************************************************************** Debugging  console *****************************************************************************/void DBG_console(){    register unsigned R31 asm("r31");    int done = 0;    DBG_stop_tracing();    PRINTF(("*** VC debug console (Return addr %x) *** ",(R31<<2)));    PRINTF(("Scream h for help.\n"));    while (!done) {        printf("Yao> ");  	scanf("%s", user_input);	gets(c_dummy); 	switch (cmd_exe_sub(ctrl_com_tbl)) {	    case 0:  break;	    case 1:  printf("Illegal command %s\n", user_input);		     break;	    case 2:  printf("Failed command %s\n", user_input);		     break;	    case -1: done = 1; break;	}    }	    DBG_start_tracing();}#endif /* DEBUG */#ifdef TRACE_ON/***************************************************************************** Poor man's logical analyser. *****************************************************************************/#define MAX_EVENT_HISTORY 3000typedef struct {    int type;    int time;    int a0, a1, a2, a3, a4;    int abv, vbv;#ifdef TRACE_PCM_TOO    int pcm_raw, pcm;#endif} transaction;static transaction *history, *event;static int	   n_traces = 0;static int	   trace_on = 0;/***************************************************************************** Allocate the trace buffer. *****************************************************************************/void    DBG_allocate_trace_buffer(){#ifdef DVD_VCD     history = event = (transaction *)dram_cached(0x20000);#else     history = event =        (transaction *)malloc(MAX_EVENT_HISTORY*sizeof(transaction));     assert(history != 0);#endif     while (event < history + MAX_EVENT_HISTORY) {        event->type = 0;        event++;     }     event = history;}/***************************************************************************** Start/stop tracing. *****************************************************************************/void	DBG_start_tracing(){    trace_on = 1;}void	DBG_stop_tracing(){    trace_on = 0;}/***************************************************************************** Log the event. *****************************************************************************/void    DBG_log_event(type, a0, a1, a2, a3, a4)int	type, a0, a1, a2, a3, a4;{    if (!trace_on) return;    event->type = type;    event->time = mvd[riface_timer2];    event->a0 = a0;    event->a1 = a1;    event->a2 = a2;    event->a3 = a3;    event->a4 = a4;    event->abv = ABV_wrptr - ABV_rdptr;    if ((event->abv)<0) event->abv += ABV_size;    event->vbv = VBV_wrptr - VBV_rdptr;    if ((event->vbv)<0) event->vbv += VBV_size;#ifdef TRACE_PCM_TOO    event->pcm = PCM_wrptr - PCM_rdptr;    if ((event->pcm)<0) event->pcm += PCM_size;    event->pcm_raw = PCM_raw_wrptr - PCM_raw_rdptr;    if ((event->pcm_raw)<0) event->pcm_raw += PCM_size;#endif    event++;    if (event==&history[MAX_EVENT_HISTORY]) event = history;    n_traces++;}char typestr[4] = {'X','I','P','B'};/***************************************************************************** Print the history. *****************************************************************************/int    DBG_print_event_history(FILE *fp){    int  i, delta_time;    transaction *what;     mvd[riface_irqmask] = 0;    fprintf(fp, "Total # of traces: %d\n", n_traces);    fprintf(fp, "VBV: %d->%d. ABV: %d->%d. PCM: %d->%d\n",	VBV_start, VBV_end, ABV_start, ABV_end, PCM_start, PCM_end);     for (i=0; i<MAX_EVENT_HISTORY; i++) {	what = &history[i];        if (what->type==0) continue;	if ((i==0)||(event==what)) delta_time = 0;        else {            delta_time = what->time - (what-1)->time;            if (delta_time<0) {		delta_time += -timer2_period;	    }        }        fprintf(fp, "%7d: ",delta_time);        fprintf(fp, "%2d ",what->type);        switch (what->type) {#ifdef LOG_TASK	    case  1:		switch (what->a0) {	    	    case 1: fprintf(fp, "Decode audio. ");	break;	    	    case 2: fprintf(fp, "Decode video. ");	break;	    	    case 3: fprintf(fp, "Start karaoke. ");	break;	    	    case 4: fprintf(fp, "Start cdda. ");	break;	    	    case 5: fprintf(fp, "Start vscale. ");	break;		}		break;	    case  2:		switch (what->a0) {	    	    case 1: fprintf(fp, "Done audio. ");	break;	    	    case 2: fprintf(fp, "Done video. ");	break;	    	    case 3: fprintf(fp, "Done karaoke. ");	break;	    	    case 4: fprintf(fp, "Done cdda. ");		break;	    	    case 5: fprintf(fp, "Done vscale. ");		break;		}		break;#endif#ifdef LOG_INT

⌨️ 快捷键说明

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