Fabio Fumi
/
send_to_sharp
Renamed
send_pc1403.cpp
- Committer:
- ffxx68
- Date:
- 2022-02-15
- Revision:
- 0:07819bc70660
- Child:
- 1:9289febf4ae9
File content as of revision 0:07819bc70660:
#include "send_pc1403.h" #include "bit_send.h" /////////////////////////////////////////////////////// // mbed objects /* Timer bit_timer; */ // volatile force main to reread from SRAM // with the new contents the interrupt wrote to it // but, since both read/write there, this should be 'protected'! // https://os.mbed.com/questions/5146/Sharing-Variables-with-Interrupts/ volatile uint32_t bit_tick_flags; static uint8_t bit_tick_count; static uint8_t bit_cycle_count; static uint32_t bit_out_value; /////////////////////////////////////////////////////// // variables from PocketTools code uint SHCc = 0 , /* Read not from bin, but from Transfile PC plus SHC-format (header included) */ SHCe = 0 ; /* End marks are the SHC Basic image included only*/ uint QTc = 0 ; /* Write to Quick-Tape wave format */ uint STc = 0 ; /* Header of SuperTape or file header of PC-1600 format is in the image included */ uint TAPc = 0 ; /* Write not to wave format but to emulator tap format (raw bytes)*/ uint Qcnt = 0 ; /* Quiet, minimal output */ uint Scnt = 0 ; /* Number of sync parameters or sync and sync spaces was defined */ uint Acnt = 0 ; /* Number of address parameters, non standard load or entry addresses */ uint Mcnt = 0 ; /* Read header parameter from a file */ double speed = 1.00 ; /* Used it for modified Pocket Computer with a CPU Speed Up switched on */ ulong pcId = 1500 ; /* ID number of the pocket computer */ ushort pcgrpId = IDENT_UNKNOWN ; // ulong pcAddr = 0 ; /* PC-specific address, used for the end of variable data of PCs with DB-tables */ bool cnvstr_upr = false ; /* Convert strings to upper, for Pokecon with SML-key not */ bool type_asm = false ; /* Image contains assembler source code (subtype), true for CASL and CAP-X */ // TODO (mr#2#): Count all warnings and errors ulong err_cnt = 0 ; /* counts minor errors */ ulong wrn_cnt = 0 ; /* counts warnings */ /** replaced by the buffered int bitSend (uint8_t bit, uint8_t invert){ uint8_t cycle_n; uint32_t theor_time = 0; bit_timer.reset(); bit_timer.start(); switch (bit ^ invert) { case 0: for ( cycle_n = 0; cycle_n < BIT_0_NCYCLES; cycle_n++) { bit_out = 1; wait_us( BIT_0_DELAY_HIGH ); bit_out = 0; wait_us( BIT_0_DELAY_LOW ); } theor_time = ( BIT_0_DELAY_LOW + BIT_0_DELAY_HIGH) * BIT_0_NCYCLES; case 1: for ( cycle_n = 0; cycle_n < BIT_0_NCYCLES; cycle_n++) { bit_out = 1; wait_us( BIT_1_DELAY_HIGH ); bit_out = 0; wait_us( BIT_1_DELAY_LOW ); } theor_time = ( BIT_1_DELAY_LOW + BIT_1_DELAY_HIGH) * BIT_1_NCYCLES; } bit_timer.stop(); return (bit_timer.read_us() - theor_time); // difference real - theoretical timing (in us), per bit } */ //////////////////////////////////////////////////////////////////////////////// // WriteBitToWav replaced from PocketTools version (writing to a WAV file) // Here we send directly signals to OUT lines int WriteBitToWav (int value, FileInfo* ptrFile) { // Calling the buffered bit sending routine if ( bitWaitSend ( value, 0 ) > MAX_BIT_TIME_ERR ) return ( ERR_NOK ) ; else return ( ERR_OK ) ; } //////////////////////////////////////////////////////////////////////////////// // Write* methods taken from Pocket-Tools source code // https://www.peil-partner.de/ifhe.de/sharp/ int WriteQuaterToWav (uint value, uint stopBits, FileInfo* ptrFile) { uint tmp ; uint ii ; int error ; // if (TAPc > 0) return (WriteQuaterToTap (value, ptrFile)); // no do { error = WriteBitToWav (0, ptrFile) ; if (error != ERR_OK) break ; for ( ii = 0 ; ii < 4 ; ++ii ) { tmp = 1 << ii ; if ( (value & tmp) == 0 ) error = WriteBitToWav (0, ptrFile) ; else error = WriteBitToWav (1, ptrFile) ; if (error != ERR_OK) break ; } if (error != ERR_OK) break ; for ( ii = 0 ; ii < stopBits ; ++ii ) { error = WriteBitToWav (1, ptrFile) ; if (error != ERR_OK) break ; } if (error != ERR_OK) break ; } while (0) ; return (error); } int WriteByteToWav (ulong value, uchar order, uchar mode, FileInfo* ptrFile) { uint lsq ; uint msq ; int error ; // if (TAPc > 0) return (WriteByteToTap (value, order, ptrFile)) ; // no // if (order == ORDER_E) return (WriteByteToEWav (value, ptrFile)) ; // no 1403 do { lsq = value & 0x0F ; msq = (value >> 4) & 0x0F ; if (order == ORDER_INV) { error = WriteQuaterToWav (lsq, Mode[mode].stopb1, ptrFile) ; if (error != ERR_OK) break ; error = WriteQuaterToWav (msq, Mode[mode].stopb2, ptrFile) ; if (error != ERR_OK) break ; } else { error = WriteQuaterToWav (msq, Mode[mode].stopb1, ptrFile) ; if (error != ERR_OK) break ; error = WriteQuaterToWav (lsq, Mode[mode].stopb2, ptrFile) ; if (error != ERR_OK) break ; } } while (0) ; return (error); } int CheckSumB1 ( ulong Byte, FileInfo* ptrFile) { ushort sum ; /* Update the checksum */ sum = ptrFile->sum + ((Byte & 0xF0) >> 4) ; if (sum > 0xFF) { ++sum ; sum &= 0xFF ; } ptrFile->sum = (sum + (Byte & 0x0F)) & 0xFF ; return (0); } int CheckSumE ( ulong Byte, // ulong* ptrSum ) FileInfo* ptrFile) { uint tmp, ii ; /* Update the checksum */ tmp = 0x80 ; for ( ii = 0 ; ii < 8 ; ++ii, tmp >>= 1 ) if ( (Byte & tmp) != 0 ) // ++ *ptrSum ; ++ ptrFile->sum ; return (0); } int WriteByteSumToWav (ulong value, uchar order, uchar mode, FileInfo* ptrFile) { int error; // ... error = WriteByteToWav (value, order, mode, ptrFile) ; if (mode == MODE_B22) ptrFile->sum += value ; else if (mode == MODE_B9) CheckSumE (value, ptrFile) ; else CheckSumB1 (value, ptrFile) ; ++ptrFile->count ; ++ptrFile->total ; switch (mode) { // ... case MODE_B14 : case MODE_B13 : if ( ptrFile->count >= BLK_NEW) { if ( (ptrFile->debug & 0x0040) > 0 ) printf(" (%02X)", (uchar) ptrFile->sum); /* Write the checksum */ error = WriteByteToWav (ptrFile->sum, order, mode, ptrFile) ; if (error != ERR_OK) break ; ptrFile->count = 0 ; ptrFile->sum = 0 ; } break ; default : // printf ("%s: Unknown Mode\n", argP) ; break ; } return (error); } int WriteSyncToWav (ulong nbSync, // FileInfo* ptrFile) { ulong ii ; int error = ERR_OK ; if (TAPc > 0) return (ERR_OK); // no do { /* Write the Synchro patern */ for ( ii = 0 ; ii < nbSync ; ++ii ) { error = WriteBitToWav (1, ptrFile) ; if (error != ERR_OK) break ; } if (error != ERR_OK) break ; } while (0) ; return (error); } ulong SwapByte (ulong byte) { return ( (byte >> 4) + (byte << 4 & 0xF0) ); } /* File name for New and Old BASIC */ int WriteSaveNameToWav (char* ptrName, uchar mode, FileInfo* ptrFile) { uint ii ; uint tmpL ; char byte ; char tmpS[20] ; int error ; if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG ptrName %s\n\r", ptrName); do { /* Uppercase the name is done in main if needed */ // tmpL = strlen (ptrName) ; for (ii = 0; ii < cLPF-1 && ptrName[ii] != '\0'; ii++) ; tmpL = ii; if (tmpL > 7) tmpL = 7 ; for ( ii = 0 ; ii < tmpL ; ++ii ) tmpS[ii] = ptrName[ii] ; tmpS[tmpL] = 0 ; //if (Qcnt == 0) printf ("Save name : %s\n", tmpS) ; // strncpy( ptrName, tmpS, cLPF-1) ; for (ii = 0; ii < cLPF-1 && ptrName[ii] != '\0'; ii++) tmpS[ii] = ptrName[ii]; /* crash? for ( ; ii < cLPF-1; ii++) tmpS[ii] = '\0'; */ tmpL = 7 - tmpL ; for ( ii = 0 ; ii < tmpL ; ++ii ) tmpS[ii] = 0 ; if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG tmpS %s\n\r", tmpS); for ( ii = tmpL ; ii < 7 ; ++ii ) { byte = (ulong) ptrName[6 - ii] ; switch (mode) { case MODE_B19 : case MODE_B20 : if (byte < 0x80) byte = CodeOld[byte] ; else byte = CodeOld[0] ; break ; default : if (byte >= 0x80) byte = 0x20 ; break ; } tmpS[ii] = (char) SwapByte(byte) ; } tmpS[7] = 0x5F ; /* Write the Name */ ptrFile->count = 0 ; ptrFile->sum = 0 ; for ( ii = 0 ; ii < 8 ; ++ii ) { error = WriteByteSumToWav (tmpS[ii], ORDER_STD, mode, ptrFile) ; if (error != ERR_OK) break ; } if (ptrFile->ident == IDENT_PC1211) error = WriteSyncToWav (151, ptrFile) ; else if (ptrFile->ident == IDENT_PC121_DAT) error = WriteSyncToWav (111, ptrFile) ; ptrFile->count = 0 ; ptrFile->sum = 0 ; } while (0) ; return (error); } int DEBUGSaveNameToWav (char* ptrName, uchar mode, FileInfo* ptrFile) { uint ii ; uint i ; ulong byte ; ulong tmpL ; char tmpS[10] ; int error ; do { /* Uppercase the name is done in main if needed */ tmpL = strlen (ptrName) ; printf("DEBUG tmpL %u\n\r", tmpL); if (tmpL > 7) tmpL = 7 ; for ( ii = 0 ; ii < tmpL ; ++ii ) { printf("DEBUG ptrName[ii] %c\n\r", ptrName[ii]); tmpS[ii] = ptrName[ii] ; } tmpS[tmpL] = 0 ; //if (Qcnt == 0) printf ("Save name : %s\n", tmpS) ; printf("DEBUG ptrName %s\n\r", ptrName); printf("DEBUG i 1 "); // strncpy( ptrName, tmpS, cLPF-1) ; for (i = 0; i < cLPF-1 && ptrName[i] != '\0'; i++) { printf("%u ", i); tmpS[i] = ptrName[i]; } printf("\n\rDEBUG i 2 "); /* crash? for ( ; i < cLPF-1; i++) { printf("%u ", i); tmpS[i] = '\0'; } */ printf("\n\rDEBUG tmpS %s\n\r", tmpS); tmpL = 7 - tmpL ; for ( ii = 0 ; ii < tmpL ; ++ii ) tmpS[ii] = 0 ; printf("DEBUG tmpS %s\n\r", tmpS); /* reverse-order bytes */ for ( ii = tmpL ; ii < 7 ; ++ii ) { byte = (ulong) ptrName[6 - ii] ; printf("DEBUG byte %u\n\r", byte); switch (mode) { case MODE_B19 : case MODE_B20 : if (byte < 0x80) byte = CodeOld[byte] ; else byte = CodeOld[0] ; break ; default : if (byte >= 0x80) byte = 0x20 ; break ; } tmpS[ii] = (char) SwapByte(byte) ; } tmpS[7] = 0x5F ; printf("DEBUG ii %u\n\r", ii); /* Write the Name */ ptrFile->count = 0 ; ptrFile->sum = 0 ; for ( ii = 0 ; ii < 8 ; ++ii ) { error = WriteByteSumToWav (tmpS[ii], ORDER_STD, mode, ptrFile) ; if (error != ERR_OK) break ; } if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG Name - Bytes was printed swapped.\n\r"); printf("DEBUG WriteSyncToWav prima\n\r"); if (ptrFile->ident == IDENT_PC1211) error = WriteSyncToWav (151, ptrFile) ; else if (ptrFile->ident == IDENT_PC121_DAT) error = WriteSyncToWav (111, ptrFile) ; printf("DEBUG WriteSyncToWav dopo\n\r"); ptrFile->count = 0 ; ptrFile->sum = 0 ; printf("DEBUG fine\n\r"); } while (0) ; return (error); } /* Head of Binary Data for New and Old series */ int WriteHeadToBinWav (ulong addr, ulong size, uchar mode, FileInfo* ptrFile) { int ii ; ulong len ; ulong tmpL ; int error ; do { /* if (Qcnt == 0) { printf ("Start Address: 0x%04X\n", (uint) addr); printf ("End Address: 0x%04X, Length: %d bytes\n", (uint) (addr + size -1), (uint) size); } */ ptrFile->count = 0 ; ptrFile->sum = 0 ; for ( ii = 0 ; ii < 4 ; ++ii ) { error = WriteByteSumToWav (0, ORDER_STD, mode, ptrFile) ; if (error != ERR_OK) break ; } /* Write the address, this method is necessary because of swapped checksums in the header. */ tmpL = ((addr >> 4) & 0xF0) + (addr >> 12) ; /* H swapped */ error = WriteByteSumToWav (tmpL, ORDER_STD, mode, ptrFile) ; if (error != ERR_OK) break ; tmpL = ((addr << 4) & 0xF0) + ((addr >> 4) & 0x0F) ;/* L swapped */ error = WriteByteSumToWav (tmpL, ORDER_STD, mode, ptrFile) ; if (error != ERR_OK) break ; /* Write the Length */ len = size - 1 ; tmpL = ((len >> 4) & 0xF0) + (len >> 12) ; error = WriteByteSumToWav (tmpL, ORDER_STD, mode, ptrFile) ; if (error != ERR_OK) break ; tmpL = ((len << 4) & 0xF0) + ((len >> 4) & 0x0F) ; error = WriteByteSumToWav (tmpL, ORDER_STD, mode, ptrFile) ; if (error != ERR_OK) break ; ptrFile->count = 0 ; ptrFile->sum = 0 ; } while (0) ; return (error); } int WriteFooterToNewWav (FileInfo* ptrFile) { int error ; do { ptrFile->count = 0 ; /* no checksum writing from here until the end */ error = WriteByteSumToWav(BAS_NEW_EOF, ORDER_STD, ptrFile->mode, ptrFile) ; // error = WriteByteSumToB13Wav (BAS_NEW_EOF, ptrFile) ; if (error != ERR_OK) break ; error = WriteByteToWav(BAS_NEW_EOF, ORDER_STD, ptrFile->mode, ptrFile) ; if (error != ERR_OK) break ; if ( (ptrFile->debug & 0x00C0) > 0 ) printf(" EOF:%02X", (uchar) BAS_NEW_EOF); error = WriteByteToWav(ptrFile->sum, ORDER_STD, ptrFile->mode, ptrFile) ; if (error != ERR_OK) break ; if ( (ptrFile->debug & 0x0040) > 0 ) printf(" (%02X)", (uchar) ptrFile->sum); /* there are 2bits more HIGH at the end of transmission (at least for PC-1402) M. NOSSWITZ */ error = WriteBitToWav (1, ptrFile) ; if (error != ERR_OK) break ; error = WriteBitToWav (1, ptrFile) ; if (error != ERR_OK) break ; /* This puts 2 bits of silence (or 2 HIGH bits alternatively) to the end of the wave file. */ /* CLOAD does not accept any sound, that could be interpreted as a start bit, */ /* during post-processing. Original CSAVE switches the signal low ms after the */ /* end of transmission, before the motor of the cassette recorder is switched off. */ /* This level out is visible in the CSAVE audio signal after the last bit. T. Muecker */ error = WriteBitToWav (3, ptrFile) ; if (error != ERR_OK) break ; error = WriteBitToWav (2, ptrFile) ; if (error != ERR_OK) break ; } while (0) ; return (error); } int WriteFooterToMemoWav (FileInfo* ptrFile) { int error ; do { error = WriteByteToWav(ptrFile->sum, ORDER_STD, ptrFile->mode, ptrFile) ; if (error != ERR_OK) break ; if ( (ptrFile->debug & 0x0040) > 0 ) printf(" (%02X)", (uchar) ptrFile->sum); error = WriteBitToWav (1, ptrFile) ; if (error != ERR_OK) break ; error = WriteBitToWav (1, ptrFile) ; if (error != ERR_OK) break ; /* This puts 2 bits of silence (or 2 HIGH bits alternatively) to the end of the wave file. */ error = WriteBitToWav (3, ptrFile) ; if (error != ERR_OK) break ; error = WriteBitToWav (2, ptrFile) ; if (error != ERR_OK) break ; } while (0) ; return (error); } ///////////////////////////////////////////////////////////////////////////// // My file-send implementation // Inspired to Pocket-Tools source code ... int FileSend ( char* FileName, char* FileStream, uint FileSize, FileInfo* ptrFile ) { int pcId = PC_ID; uchar type ; uint32_t ii ; uint32_t nbByte; uint32_t nbSync = N_SYNC_BITS; uint32_t addr; int error ; char inVal; // BIN file stored statically, until I integrate an SD-Card... nbByte = FileSize; ptrFile->nbSync = nbSync; if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG ptrFile->ident %u\n\r",ptrFile->ident); if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG nbSync %u\n\r",nbSync); if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG nbByte %u\n\r",nbByte); switch (ptrFile->ident) { /* . . .*/ case IDENT_NEW_BIN : pcgrpId = GRP_NEW ; /*or GRP_EXT */ type = TYPE_BIN ; break ; /* . . .*/ case IDENT_NEW_BAS : pcgrpId = GRP_NEW ; type = TYPE_IMG ; break ; default : printf ("%s: Unknown Ident\n", argP) ; return (ERR_ARG); } /* if (pcgrpId == GRP_E || pcgrpId == GRP_G || pcgrpId == GRP_16) { . . . } else { // PC-1211 to PC-1500, QTape */ if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG WriteSyncToWav\n\r"); error = WriteSyncToWav (nbSync, ptrFile) ; /* . . . */ if (error != ERR_OK) return ( error ) ; switch (pcId) { /* . . . */ case 1403: /* if (type == TYPE_BIN && Acnt==0 && SHCc==0 && addr==0) */ addr = TYPE_BIN_ADDR; /* . . . */ break; default : printf ("%s: Pocket computer %d is not implemented\n", argP, pcId) ; // MoreInfo (ERR_ARG); error = ERR_ARG ; // break ; } if (error != ERR_OK) return ( error ) ; /* ... else { // PC-121x ... PC-1475 */ if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG set Header Mode\n\r"); switch (ptrFile->ident) { /* Header Mode */ case IDENT_PC1211 : ptrFile->mode = ptrFile->mode_h = MODE_B20 ; break ; case IDENT_PC121_DAT : case IDENT_OLD_BAS : case IDENT_OLD_DAT : case IDENT_OLD_BIN : case IDENT_OLD_MEM : ptrFile->mode = ptrFile->mode_h = MODE_B19 ; break ; case IDENT_NEW_TEL : case IDENT_NEW_SCD : case IDENT_NEW_NOT : case IDENT_NEW_CRD : case IDENT_NEW_CSL : case IDENT_NEW_BAS : case IDENT_EXT_BAS : case IDENT_NEW_DAT : case IDENT_NEW_BIN : ptrFile->mode = ptrFile->mode_h = MODE_B16 ; break ; default : printf ("%s: Unknown Ident\n", argP) ; ptrFile->mode = ptrFile->mode_h = MODE_B21 ; return (ERR_ARG); } if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG Header ptrFile->mode_h %u\n\r",ptrFile->mode_h); /* Write the TAPE code */ if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG Write the TAPE code\n\r"); error = WriteByteToWav ( (ulong) ptrFile->ident, ORDER_STD, ptrFile->mode_h, ptrFile) ; if (error != ERR_OK) return ( error ) ; /* Write the Name */ if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG Write the Name\n\r"); error = WriteSaveNameToWav ( FileName, ptrFile->mode_h, ptrFile) ; if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG error (ERR_OK) %d (%d)\n\r", error, ERR_OK); if (error != ERR_OK) return ( error ) ; if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG set Body Data Mode\n\r"); switch (ptrFile->ident) { /* Body Data Mode */ case IDENT_PC1211 : ptrFile->mode = MODE_B20 ; break ; case IDENT_PC121_DAT : case IDENT_OLD_BAS : case IDENT_OLD_BIN : case IDENT_OLD_MEM : ptrFile->mode = MODE_B19 ; break ; case IDENT_OLD_DAT : case IDENT_NEW_DAT : ptrFile->mode = MODE_B15 ; break ; case IDENT_EXT_BAS : case IDENT_NEW_BAS : case IDENT_NEW_CSL : case IDENT_NEW_TEL : case IDENT_NEW_SCD : case IDENT_NEW_NOT : case IDENT_NEW_CRD : case IDENT_NEW_BIN : // TODO (mr#2#): Check whitch MODE_B13 or _B14 if (cnvstr_upr && pcId < 1440) ptrFile->mode = MODE_B13 ; /*older part of new series*/ else ptrFile->mode = MODE_B14 ; /*new series and extended series*/ break ; default : printf ("%s: Unknown Ident\n", argP) ; return ( ERR_ARG ); } if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG Body ptrFile->mode %u\n\r", ptrFile->mode); ptrFile->total = 0 ; /* count bytes of body only */ switch (ptrFile->ident) { /* header was written, write all data now */ /* ... case ... */ case IDENT_NEW_BAS : case IDENT_NEW_CSL : case IDENT_EXT_BAS : if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG Write the datas\n\r"); /* Write the datas */ // info.mode = MODE_B13 ; /*PC-1403 and newer should be MODE_14 */ /* the older simple algorithm seems to work as well, but this is now, what the PC does originally */ for ( ii = 0 ; ii < nbByte - 1 ; ++ii ) { if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG LOOP ii %u\n\r", ii); inVal = FileStream[ii] ; // fgetc (srcFd) ; if ( inVal == EOF ) break ; if ( inVal == BAS_NEW_EOF ) { if (ptrFile->count + 1 == BLK_NEW && ptrFile->sum == 0xE1) { /* Constellation will generate 2-times BAS_NEW_EOF */ printf ("\nERROR %i at %lu. byte, usually the low byte of a BASIC line number\n", ERR_SUM, ptrFile->total) ; printf ("This binary constellation activates the CLOAD bug of this series. The line\n") ; printf ("number must be changed or minor changes done in the BASIC text before.\n") ; /* Seldom Bug in CLOAD, for PC-1402/(01) at known ROM address: 40666 */ if ((ptrFile->debug & 0x800) == 0 ) { error = ERR_SUM ; break ; } } } error = WriteByteSumToWav ( (uint) inVal, ORDER_STD, ptrFile->mode, ptrFile) ; if (error != ERR_OK) break ; } if (error != ERR_OK) break ; if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG ii %u\n\r", ii); inVal = FileStream[ii] ; // fgetc (srcFd) ; /* Read the last byte before EOF mark */ if (inVal == EOF) break ; if (inVal == BAS_NEW_EOF) { /* EOF mark should not be included for this file type normally*/ if (Qcnt == 0) printf ("End of File mark %i should not be included in the image\n", inVal) ; /* if end of block, then an additional checksum would be written, but this does work anyhow */ } else { if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG last byte: %02X\n\r", (uchar) inVal); error = WriteByteToWav ( (uint) inVal, ORDER_STD, ptrFile->mode, ptrFile) ; if (error != ERR_OK) break ; CheckSumB1 ((uint) inVal, ptrFile) ; /* never write the checksum before BAS_NEW_EOF */ ++ptrFile->total ; ++ptrFile->count ; /* for debug purposes only, WriteFooter will reset it */ } /* Write the END code */ if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG WriteFooterToNewWav prima\n\r"); error = WriteFooterToNewWav (ptrFile) ; break ; // IDENT_NEW_BAS, IDENT_EXT_BAS case IDENT_NEW_BIN : /* Write the address and length */ error = WriteHeadToBinWav (addr, nbByte, ptrFile->mode_h, ptrFile) ; if (error != ERR_OK) break ; /* no break */ case IDENT_NEW_TEL : case IDENT_NEW_SCD : case IDENT_NEW_NOT : case IDENT_NEW_CRD : /* Write the datas */ for ( ii = 0 ; ii < nbByte - 1 ; ++ii ) { inVal = FileStream[ii] ; // fgetc (srcFd) ; if (inVal == EOF) break ; // Should not happen ... error = WriteByteSumToWav ( (uint) inVal, ORDER_STD, ptrFile->mode, ptrFile) ; if (error != ERR_OK) break ; } if (error != ERR_OK) break ; inVal = FileStream[ii] ; // fgetc (srcFd) ; /* Read the last byte before EOF mark */ if (inVal == EOF) break ; if ( (ptrFile->debug & 0x0040) > 0 ) printf(" %02X", (uchar) inVal); error = WriteByteToWav ( (uint) inVal, ORDER_STD, ptrFile->mode, ptrFile) ; if (error != ERR_OK) break ; CheckSumB1 ( (uint) inVal, ptrFile ) ; /* never write the checksum before BAS_NEW_EOF */ ++ptrFile->total ; ++ptrFile->count ; /* for debug purposes only, WriteFooter will reset it */ /* Write the END code */ if ( ptrFile->ident == IDENT_NEW_BIN) error = WriteFooterToNewWav ( ptrFile ) ; else WriteFooterToMemoWav ( ptrFile ) ; break ; // IDENT_NEW_BIN and IDENT_NEW_Memos default: printf ("%s: Unknown Ident\n", argP) ; error = ERR_ARG; break; } if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG FileSend error %d\n\r", error); return (error); }