// ends logging void waveLogStop(void) { unsigned int nLen = 0, temp; if (waveLogEnable == 0) { return; } if (waveLogFile != (FILE *)NULL) { // get total file length fseek(waveLogFile, 0, SEEK_END); nLen = ftell(waveLogFile); // set RIFF chunk size (total minus 8 for the RIFF and length) fseek(waveLogFile, 4, SEEK_SET); nLen -= 8; temp = Endian32_Swap(nLen); fwrite(&temp, 4, 1, waveLogFile); // set WAVE chunk size (total - 8 - 36 more for the WAVE header stuff) fseek(waveLogFile, 0x28, SEEK_SET); nLen -= 36; temp = Endian32_Swap(nLen); fwrite(&temp, 4, 1, waveLogFile); fclose(waveLogFile); waveLogFile = (FILE *)NULL; } }
// begin wave logging void waveLogStart(void) { INT32 ua = 0; INT16 wFormatTag = 0; // format 1 is linear PCM INT16 nChannels = 0; INT32 nSamplesPerSec = 0, nAvgBytesPerSec = 0; INT16 nBlockAlign = 0, wBitsPerSample = 0; // do not create file if disabled if (waveLogEnable == 0) { return; } waveLogStop(); // force end of any old log waveLogFile = fopen(wlpath, "wb"); if (waveLogFile == (FILE*)NULL) { fprintf(stderr, "Unable to create .WAV log %s", wlpath); return; } // create the .WAV header nChannels = Endian16_Swap(2); nSamplesPerSec = Endian32_Swap(Machine->sample_rate); nAvgBytesPerSec = Endian32_Swap((Machine->sample_rate*4)); wBitsPerSample = Endian16_Swap(16); nBlockAlign = Endian16_Swap((nChannels * (wBitsPerSample/8))); ua = Endian32_Swap(0x10); wFormatTag = Endian16_Swap(1); fwrite("RIFF WAVEfmt ", 1, 0x10, waveLogFile); fwrite(&ua, 4, 1, waveLogFile); fwrite(&wFormatTag, sizeof(wFormatTag), 1, waveLogFile); fwrite(&nChannels, sizeof(nChannels), 1, waveLogFile); fwrite(&nSamplesPerSec, sizeof(nSamplesPerSec), 1, waveLogFile); fwrite(&nAvgBytesPerSec, sizeof(nAvgBytesPerSec), 1, waveLogFile); fwrite(&nBlockAlign, sizeof(nBlockAlign), 1, waveLogFile); fwrite(&wBitsPerSample, sizeof(wBitsPerSample), 1, waveLogFile); fwrite("data ", 8, 1, waveLogFile); }
/* shared_val1 = next offset to use in block (Always 0 for v1) */ enum backup_state_ret restore_state_begin_v1 (struct backup_info *info, void *data, unsigned size, unsigned *consumed) { struct backup_head *head = data; if (size == 0) { info->err_msg = "Internal error: Restore buffer empty"; return bsError; } switch (head->magic) { case TB_MAGIC: break; case TB_ENDIAN: info->back_flags |= RF_ENDIAN; break; case TB3_MAGIC: case TB3_ENDIAN: info->state_machine = &restore_v3; /* Return and let it call back into v3 handler */ return bsMoreData; break; default: info->err_msg = "Unknown backup format"; return bsError; } /* Copy header fields into backup info */ if (info->back_flags & RF_ENDIAN) { info->back_flags |= Endian32_Swap (head->flags); info->nsectors = Endian32_Swap (head->nsectors); info->nparts = Endian32_Swap (head->nparts); info->nblocks = Endian32_Swap (head->nblocks); info->nmfs = Endian32_Swap (head->mfspairs); } else { info->back_flags |= head->flags; info->nsectors = head->nsectors; info->nparts = head->nparts; info->nblocks = head->nblocks; info->nmfs = head->mfspairs; } /* Allocate storage for backup description */ info->parts = calloc (sizeof (struct backup_partition), info->nparts); info->blocks = calloc (sizeof (struct backup_block), info->nblocks); info->mfsparts = calloc (sizeof (struct backup_partition), info->nmfs); if (!info->parts || !info->blocks || !info->mfsparts) { if (info->parts) free (info->parts); info->parts = 0; info->nparts = 0; if (info->blocks) free (info->blocks); info->blocks = 0; info->nblocks = 0; if (info->mfsparts) free (info->mfsparts); info->mfsparts = 0; info->nmfs = 0; info->err_msg = "Memory exhausted (Begin restore)"; return bsError; } if (info->back_flags & BF_64) { if (info->bitsize == 32) { info->err_msg = "Restore of V1 format backup files does not support converting MFS structure type"; return 1; } } else { if (info->bitsize == 64) { info->err_msg = "Restore of V1 format backup files does not support converting MFS structure type"; return 1; } } /* v1 backup has no other data in first block */ *consumed = 1; info->shared_val1 = 0; return bsNextState; }