acmd.c 9.17 KB
#include <stdio.h>
#include <stdlib.h>
#include <abi.h>

static char usage[] = "-verbose <filename>";

main(int argc, char **argv)
{
    int         ch;
    extern char *optarg;
    extern int  optind;
    int         errflg=0;
    char        *ifile;
    int         verbose;
    FILE        *cmds;
    int         rv;
    int         done=0;
    Acmd        cmd;
    float	temp;
    
    /*************************************************************
     * parse the command line arguments
     *************************************************************/
    while ((ch = getopt(argc, argv, "v")) != EOF) {        
        switch (ch) {
	    case 'v':
                verbose = 1;
		break;
            case '?':
                errflg++;
                break;
        }
    }

    if (errflg || optind == argc) {
        (void)fprintf(stderr, "%s %s\n", argv[0], usage);
        exit (2);
    }

    ifile = argv[optind++];
    if (optind != argc) {
	fprintf(stderr, "warning: only first file (%s) used, rest ignored\n",
	   ifile);
    }

    cmds = fopen(ifile, "r");
    if (!cmds) {
        printf("Can't open command file\n");
        exit(1);
    }
    
    while (fread (&cmd, sizeof(Acmd), 1, cmds) > 0) {
        switch (cmd.adpcm.cmd) {
            case A_SPNOOP:
                printf("SPNOOP: %d\n", cmd.adpcm.cmd);
                printf("\n");
                break;
                
            case A_ADPCM:
                printf("ADPCM: %d\n", cmd.adpcm.cmd);
                printf("\tflags: 0x%x\n", cmd.adpcm.flags);
                printf("\tgain: 0x%x\n", cmd.adpcm.gain);
                printf("\tsegment: %d\n", cmd.adpcm.addr>>26);
                printf("\tstate offset: 0x%x\n", cmd.adpcm.addr & 0x03ffffff);
                printf("\n");
                break;
                
            case A_CLEARBUFF:
                printf("Clear Buff: %d\n", cmd.adpcm.cmd);
                printf("\tpad1: 0x%x\n", cmd.clearbuff.pad1);
                printf("\tdmem: 0x%x\n", cmd.clearbuff.dmem);
                printf("\tpad2: 0x%x\n", cmd.clearbuff.pad2);
                printf("\tcount: 0x%x, %d\n", cmd.clearbuff.count, cmd.clearbuff.count);
                printf("\n");
                break;
                
            case A_ENVMIXER:
                printf("Envelope: %d\n", cmd.adpcm.cmd);
                printf("\tflags: 0x%x\n", cmd.envelope.flags);
                printf("\tpad1: 0x%x\n", cmd.envelope.pad1);
                printf("\tstate offset: 0x%x\n", cmd.envelope.addr);
                printf("\n");
                break;
                
            case A_LOADBUFF:
                printf("Load Buff: %d\n", cmd.adpcm.cmd);
                printf("\tpad1: 0x%x\n", cmd.loadbuff.pad1);
                printf("\tsegment: %d\n", cmd.loadbuff.addr>>26);
                printf("\tdram offset: 0x%x\n", cmd.loadbuff.addr & 0x03ffffff);
                printf("\n");
                break;
                
            case A_RESAMPLE:
                printf("Resample: %d\n", cmd.adpcm.cmd);
                printf("\tflags: 0x%x\n", cmd.resample.flags);
                printf("\tpitch: 0x%x, %f\n", cmd.resample.pitch, (float)cmd.resample.pitch/(float)0x8000);
                printf("\tsegment: %d\n", cmd.resample.addr>>26);
                printf("\tstate offset: 0x%x\n", cmd.resample.addr & 0x03ffffff);
                printf("\n");
                break;
                
            case A_SAVEBUFF:
                printf("Save Buff: %d\n", cmd.adpcm.cmd);
                printf("\tpad1: 0x%x\n", cmd.savebuff.pad1);
                printf("\tsegment: %d\n", cmd.savebuff.addr>>26);
                printf("\tdram offset: 0x%x\n", cmd.savebuff.addr & 0x03ffffff);
                printf("\n");
                break;
                
            case A_SEGMENT:
                printf("Segment: %d\n", cmd.adpcm.cmd);
                printf("\tpad1: 0x%x\n", cmd.segment.pad1);
                printf("\tpad2: 0x%x\n", cmd.segment.pad2);
                printf("\tnumber: 0x%x\n", cmd.segment.number);
                printf("\tbase: 0x%x\n", cmd.segment.base);
                printf("\n");
                break;
                
	      case A_SETBUFF:
		if (cmd.setbuff.flags & A_AUX) {
		    printf("Set Buff: %d\n", cmd.adpcm.cmd);
		    printf("\tflags: 0x%x = %s\n", cmd.setbuff.flags, "A_AUX");
		    printf("\tdmoutR: 0x%x\n", cmd.setbuff.dmemin);
		    printf("\tdmauxL: 0x%x\n", cmd.setbuff.dmemout);
		    printf("\tdmauxR: 0x%x\n", cmd.setbuff.count);
		    printf("\n");
		}
		else {
		    printf("Set Buff: %d\n", cmd.adpcm.cmd);
		    printf("\tflags: 0x%x\n", cmd.setbuff.flags);
		    printf("\tdmemin: 0x%x\n", cmd.setbuff.dmemin);
		    printf("\tdmemout: 0x%x\n", cmd.setbuff.dmemout);
		    printf("\tcount: 0x%x, %d\n", cmd.setbuff.count, cmd.setbuff.count);
		    printf("\n");
		    break;
		}
		break;
                
	      case A_SETVOL:
		if (cmd.setvol.flags & A_AUX) {
		    printf("Set Vol: %d\n", cmd.adpcm.cmd);
		    printf("\tflags: 0x%x = %s\n", cmd.setvol.flags, "A_AUX");
		    printf("\tdry amount: 0x%x\n", cmd.setvol.vol);
		    printf("\tunused: 0x%x\n", cmd.setvol.voltgt);
		    printf("\twet amount: 0x%x\n", cmd.setvol.volrate);
		    printf("\n");
		}
		else if (cmd.setvol.flags & A_VOL) {
		    if (cmd.setvol.flags & A_LEFT) {
			printf("Set Vol: %d\n", cmd.adpcm.cmd);
			printf("\tflags: 0x%x = %s\n", cmd.setvol.flags, "A_VOL | A_LEFT");
			printf("\tvol left: 0x%x\n", cmd.setvol.vol);
			printf("\tunused: 0x%x\n", cmd.setvol.voltgt);
			printf("\tunused: 0x%x\n", cmd.setvol.volrate);
			printf("\n");
		    }
		    else{
			printf("Set Vol: %d\n", cmd.adpcm.cmd);
			printf("\tflags: 0x%x = %s\n", cmd.setvol.flags, "A_VOL | A_RIGHT");
			printf("\tvol right: 0x%x\n", cmd.setvol.vol);
			printf("\tunused: 0x%x\n", cmd.setvol.voltgt);
			printf("\tunused: 0x%x\n", cmd.setvol.volrate);
			printf("\n");
		    }
		}
		else if (cmd.setvol.flags & A_LEFT) {
		    printf("Set Vol: %d\n", cmd.adpcm.cmd);
		    printf("\tflags: 0x%x = %s\n", cmd.setvol.flags, "A_RATE | A_LEFT");
		    printf("\ttarget left: 0x%x\n", cmd.setvol.vol);
		    printf("\tinteger rate left: 0x%x\n", cmd.setvol.voltgt);
		    printf("\tfractional rate left: 0x%x\n", cmd.setvol.volrate);
		    printf("\trate left: %f\n", (1.0*cmd.setvol.voltgt) + ((float)cmd.setvol.volrate/(float)0xffff));
		    printf("\n");
		}
		else{
		    printf("Set Vol: %d\n", cmd.adpcm.cmd);
		    printf("\tflags: 0x%x = %s\n", cmd.setvol.flags, "A_RATE | A_RIGHT");
		    printf("\ttarget right: 0x%x\n", cmd.setvol.vol);
		    printf("\tinteger rate right: 0x%x\n", cmd.setvol.voltgt);
		    printf("\tfractional rate right: 0x%x\n", cmd.setvol.volrate);
		    printf("\trate right: %f\n", (1.0*cmd.setvol.voltgt) + ((float)cmd.setvol.volrate/(float)0xffff));
		    printf("\n");
		}
                break;

            case A_DMEMMOVE:
                printf("Dmem Move: %d\n", cmd.adpcm.cmd);
                printf("\tpad1: 0x%x\n", cmd.dmemmove.pad1);
                printf("\tdmemin: 0x%x\n", cmd.dmemmove.dmemin);
                printf("\tdmemout: 0x%x\n", cmd.dmemmove.dmemout);
                printf("\tcount: 0x%x\n", cmd.dmemmove.count);
                printf("\n");
                break;

            case A_LOADADPCM:
                printf("Load Adpcm: %d\n", cmd.adpcm.cmd);
                printf("\tpad1: 0x%x\n", cmd.loadadpcm.pad1);
                printf("\tcount: 0x%x\n", cmd.loadadpcm.count);
                printf("\tsegment: %d\n", cmd.loadadpcm.addr>>26);
                printf("\tdram offset: 0x%x\n", cmd.loadadpcm.addr & 0x03ffffff);
                printf("\n");
                break;
                printf("\n");
                break;

            case A_MIXER:
                printf("Mixer: %d\n", cmd.adpcm.cmd);
                printf("\tflags: 0x%x\n", cmd.mixer.flags);
		temp = (float)((short)cmd.mixer.gain)/(float)0x7fff;
                printf("\tgain: 0x%x, %f\n", cmd.mixer.gain, temp);
                printf("\tdmemin: 0x%x\n", cmd.mixer.dmemi);
                printf("\tdmemout: 0x%x\n", cmd.mixer.dmemo);
                printf("\n");
                break;
                
            case A_INTERLEAVE:
                printf("Interleave: %d\n", cmd.interleave.cmd);
                printf("\tpad1: 0x%x\n", cmd.interleave.pad1);
                printf("\tpad2: 0x%x\n", cmd.interleave.pad2);
                printf("\tLeft input: %d\n", cmd.interleave.inL);
                printf("\tRight input: %d\n", cmd.interleave.inR);
                printf("\n");
                break;
                
            case A_POLEF:
                printf("Polef: %d\n", cmd.polef.cmd);
                printf("\tflags: 0x%x\n", cmd.polef.flags);
                printf("\tgain: %d\n", cmd.polef.gain);
                printf("\tstate offset: 0x%x\n", cmd.polef.addr);
                printf("\n");
                break;
                
            default:
                printf("Unknown Acmd: 0x%x\n", cmd.adpcm.cmd);
                printf("\tflags: 0x%x\n", cmd.adpcm.flags);
                printf("\taud0ls: 0x%x\n", cmd.adpcm.gain);
                printf("\taud1ms: %d\n", cmd.adpcm.addr>>16);
                printf("\taud1ls: 0x%x\n", cmd.adpcm.addr & 0xffff);
                printf("\n");
                break;
        }        
    }
}