int main(int argc, char **argv) { // device memory real *psi_d, *z_d; size_t fSize = sizeof(real); /* grid dimensions */ unsigned int Nx = 513, Ny = 513; // omitting boundaries unsigned int nGridPoints = (Nx-2)*(Ny-2); cudaMalloc((void **) &psi_d, (nGridPoints+1)*fSize); cudaMalloc((void **) &z_d, (nGridPoints+1)*fSize); /* initialization */ fillArray(psi_d, 0.0, nGridPoints+1); fillArray(z_d, 1.0, nGridPoints+1); checkCudaError("Initialization of grid"); // for timing purposes cudaEvent_t start, stop; cudaEventCreate(&start); cudaEventCreate(&stop); // start timer cudaEventRecord(start,0); /* Call the poisson solver, right hand side * is stored on the device in z_d (make sure the data * is copied from CPU to GPU!), result is stored in * psi_d (on the GPU/device). * Here NX-2 is the width of the grid's interior * (without the boundaries). */ cuPoisson((Nx-2), psi_d, z_d); // stop timer cudaEventRecord(stop,0); cudaEventSynchronize(stop); float computationTime; cudaEventElapsedTime(&computationTime, start, stop); printf("Computation time was %.5f seconds.\n\n", computationTime/1000.0); printf("Writing result to disk...\n"); // write result to file writeBinaryFile(Nx, Ny, psi_d, "data.dat"); printf("done\n"); return EXIT_SUCCESS; }
/* ***************************************************************************************************** */ int writeLittleEndianBinaryFile(char *binaryFileName, int nItemsToWrite, float *arrayToWrite) { // Pinnacle doses always written in BIG_ENDIAN format... Check if need to swab..... int swab_flag = 0; switch( (check_byte_order()) ) { case BIG_ENDIAN: swab_flag=1; break; case LITTLE_ENDIAN: break; default: eprintf("\n ERROR: Indeterminate Byte Order\n"); return(FAIL); } if(OK != writeBinaryFile(binaryFileName, nItemsToWrite, arrayToWrite, swab_flag) ) { printf("\n ERROR: Writing dose file %s", binaryFileName); return(FAIL); } return(OK); }
int main(int argc, char *argv[ ]) { int i; FILE *infile, *outfile; if (argc < 3) { printf("XGMTool %s - Stephane Dallongeville - copyright 2016\n", version); printf("\n"); printf("Usage: xgmtool inputFile outputFile <options>\n"); printf("XGMTool can do the following operations:\n"); printf(" - Optimize and reduce size of Sega Megadrive VGM file\n"); printf(" Note that it won't work correctly on VGM file which require sub frame accurate timing.\n"); printf(" - Convert a Sega Megadrive VGM file to XGM file\n"); printf(" - Convert a XGM file to Sega Megadrive VGM file\n"); printf(" - Compile a XGM file into a binary file (XGC) ready to played by the Z80 XGM driver\n"); printf(" - Convert a XGC binary file to XGM file (experimental)\n"); printf(" - Convert a XGC binary file to Sega Megadrive VGM file (experimental)\n"); printf("\n"); printf("Optimize VGM:\n"); printf(" xgmtool input.vgm output.vgm\n"); printf("\n"); printf("Convert VGM to XGM:\n"); printf(" xgmtool input.vgm output.xgm\n"); printf("\n"); printf("Convert and compile VGM to binary/XGC:\n"); printf(" xgmtool input.vgm output.bin\n"); printf(" xgmtool input.vgm output.xgc\n"); printf("\n"); printf("Convert XGM to VGM:\n"); printf(" xgmtool input.xgm output.vgm\n"); printf("\n"); printf("Compile XGM to binary/XGC:\n"); printf(" xgmtool input.xgm output.bin\n"); printf(" xgmtool input.xgm output.xgc\n"); printf("\n"); printf("Convert XGC to XGM (experimental):\n"); printf(" xgmtool input.xgc output.xgm\n"); printf("\n"); printf("Compile XGC to VGM (experimental):\n"); printf(" xgmtool input.xgc output.vgm\n"); printf("\n"); printf("The action xmgtool performs is dependant from the input and output file extension.\n"); printf("Supported options:\n"); printf("-s\tenable silent mode (no message except error and warning).\n"); printf("-v\tenable verbose mode.\n"); printf("-n\tforce NTSC timing (only meaningful for VGM to XGM conversion).\n"); printf("-p\tforce PAL timing (only meaningful for VGM to XGM conversion).\n"); printf("-di\tdisable PCM sample auto ignore (it can help when PCM are not properly extracted).\n"); printf("-dr\tdisable PCM sample rate auto fix (it can help when PCM are not properly extracted).\n"); printf("-kf\tenable delayed KEY OFF event when we have KEY ON/OFF in a single frame (it can fix incorrect instrument sound).\n"); exit(1); } sys = SYSTEM_AUTO; silent = false; verbose = false; sampleIgnore = true; sampleRateFix = true; delayKeyOff = false; // Open source for binary read (will fail if file does not exist) if ((infile = fopen(argv[1], "rb")) == NULL) { printf("Error: the source file %s could not be opened\n", argv[1]); exit(2); } // test open output for write if ((outfile = fopen(argv[2], "wb")) == NULL) { printf("Error: the output file %s could not be opened\n", argv[2]); exit(3); } // can close fclose(outfile); // options for(i = 3; i < argc; i++) { if (!strcasecmp(argv[i], "-s")) { silent = true; verbose = false; } else if (!strcasecmp(argv[i], "-v")) { verbose = true; silent = false; } else if (!strcasecmp(argv[i], "-di")) sampleIgnore = false; else if (!strcasecmp(argv[i], "-dr")) sampleRateFix = false; else if (!strcasecmp(argv[i], "-kf")) delayKeyOff = true; else if (!strcasecmp(argv[i], "-n")) sys = SYSTEM_NTSC; else if (!strcasecmp(argv[i], "-p")) sys = SYSTEM_PAL; else printf("Warning: option %s not recognized (ignored)\n", argv[i]); } // silent mode has priority if (silent) verbose = false; char* inExt = getFileExtension(argv[1]); char* outExt = getFileExtension(argv[2]); int errCode = 0; if (!strcasecmp(inExt, "VGM")) { if ((!strcasecmp(outExt, "VGM")) || (!strcasecmp(outExt, "XGM")) || (!strcasecmp(outExt, "BIN")) || (!strcasecmp(outExt, "XGC"))) { // VGM optimization int inDataSize; unsigned char* inData; int outDataSize; unsigned char* outData; VGM* vgm; VGM* optVgm; // load file inData = readBinaryFile(argv[1], &inDataSize); if (inData == NULL) exit(1); // load VGM if (sys == SYSTEM_NTSC) inData[0x24] = 60; else if (sys == SYSTEM_PAL) inData[0x24] = 50; vgm = VGM_create1(inData, inDataSize, 0); if (vgm == NULL) exit(1); // optimize optVgm = VGM_createFromVGM(vgm, true); if (optVgm == NULL) exit(1); VGM_convertWaits(optVgm); VGM_cleanCommands(optVgm); VGM_cleanSamples(optVgm); VGM_fixKeyCommands(optVgm); // VGM output if (!strcasecmp(outExt, "VGM")) { // get byte array outData = VGM_asByteArray(optVgm, &outDataSize); if (outData == NULL) exit(1); // write to file writeBinaryFile(outData, outDataSize, argv[2]); } else { XGM* xgm; // convert to XGM xgm = XGM_createFromVGM(optVgm); if (xgm == NULL) exit(1); // XGM output if (!strcasecmp(outExt, "XGM")) { // get byte array outData = XGM_asByteArray(xgm, &outDataSize); } else { XGM* xgc; // convert to XGC (compiled XGM) xgc = XGC_create(xgm); if (xgc == NULL) exit(1); // get byte array outData = XGC_asByteArray(xgc, &outDataSize); } if (outData == NULL) exit(1); // write to file writeBinaryFile(outData, outDataSize, argv[2]); } } else { printf("Error: the output file %s is incorrect (should be a VGM, XGM or BIN/XGC file)\n", argv[2]); errCode = 4; } } else if (!strcasecmp(inExt, "XGM")) { if ((!strcasecmp(outExt, "VGM")) || (!strcasecmp(outExt, "BIN")) || (!strcasecmp(outExt, "XGC"))) { // XGM to VGM int inDataSize; unsigned char* inData; int outDataSize; unsigned char* outData; XGM* xgm; // load file inData = readBinaryFile(argv[1], &inDataSize); if (inData == NULL) exit(1); // load XGM xgm = XGM_createFromData(inData, inDataSize); if (xgm == NULL) exit(1); // VGM conversion if (!strcasecmp(outExt, "VGM")) { VGM* vgm; // convert to VGM vgm = VGM_createFromXGM(xgm); if (vgm == NULL) exit(1); // get byte array outData = VGM_asByteArray(vgm, &outDataSize); } else { XGM* xgc; // convert to XGC (compiled XGM) xgc = XGC_create(xgm); if (xgc == NULL) exit(1); // get byte array outData = XGC_asByteArray(xgc, &outDataSize); } if (outData == NULL) exit(1); // write to file writeBinaryFile(outData, outDataSize, argv[2]); } else { printf("Error: the output file %s is incorrect (should be a VGM or BIN/XGC file)\n", argv[2]); errCode = 4; } } else if (!strcasecmp(inExt, "XGC")) { if ((!strcasecmp(outExt, "VGM")) || (!strcasecmp(outExt, "XGM"))) { // XGC to XGM int inDataSize; unsigned char* inData; int outDataSize; unsigned char* outData; XGM* xgm; // load file inData = readBinaryFile(argv[1], &inDataSize); if (inData == NULL) exit(1); // load XGM xgm = XGM_createFromXGCData(inData, inDataSize); if (xgm == NULL) exit(1); // VGM conversion if (!strcasecmp(outExt, "VGM")) { VGM* vgm; // convert to VGM vgm = VGM_createFromXGM(xgm); if (vgm == NULL) exit(1); // get byte array outData = VGM_asByteArray(vgm, &outDataSize); } else { // get byte array outData = XGM_asByteArray(xgm, &outDataSize); } if (outData == NULL) exit(1); // write to file writeBinaryFile(outData, outDataSize, argv[2]); } else { printf("Error: the output file %s is incorrect (should be a XGM or VGM file)\n", argv[2]); errCode = 4; } } else { printf("Error: the input file %s is incorrect (should be a VGM, XGM or XGC file)\n", argv[1]); errCode = 4; } fclose(infile); remove("tmp.bin"); return errCode; }
libusb_device_handle* start(int argc, char **argv) { libusb_device_handle *handler = NULL; char firmwareFilename[4096]; handler = b96_init_device(); if (handler == NULL) { return NULL; } printf ("Handler: %p\n",handler); if (find_firmware("adfudec.bin", firmwareFilename, sizeof(firmwareFilename))==NULL) { error_at_line(0,0,__FILE__,__LINE__, "Error: Cannot find adfudec.bin"); return handler; } writeBinaryFile(handler, '\x05', 0xe406f000u, firmwareFilename, 0, NULL); sleep(1); if (find_firmware("bootloader.bin", firmwareFilename, sizeof(firmwareFilename))==NULL) { error_at_line(0,0,__FILE__,__LINE__, "Error: Cannot find bootloader.bin"); return handler; } writeBootloaderBin(handler, firmwareFilename); sleep(1); unknownCMD07(handler); sleep(10); libusb_close(handler); handler = b96_init_device(); if (handler == NULL) { return NULL; } setuid(getuid()); if (find_firmware("bl31.bin", firmwareFilename, sizeof(firmwareFilename))==NULL) { error_at_line(0,0,__FILE__,__LINE__, "Error: Cannot find bl31.bin"); return handler; } /* load bl31.bin to 0x1f000000 */ writeBinaryFile(handler, '\xcd' ,0x13, firmwareFilename, 0x1f000000u, NULL); if (find_firmware("bl32.bin", firmwareFilename, sizeof(firmwareFilename))==NULL) { error_at_line(0,0,__FILE__,__LINE__, "Error: Cannot find bl32.bin"); return handler; } /* load bl32.bin to 0x1f202000 */ writeBinaryFile(handler, '\xcd', 0x13, firmwareFilename, 0x1f202000u, NULL); /* load u-boot-dtb.img to 0x10ffffc0. (Note: u-boot is at 0x11000000, -0x40 is the header */ writeBinaryFile(handler, '\xcd', 0x13, argv[1], 0x10ffffc0u, NULL); sleep(2); /* jump to 0x1f000000 (bl31.bin)*/ unknownCMD50(handler, 0x1f000000u); sleep(2); libusb_close(handler); handler = NULL; return handler; }