Fabio Fumi
/
send_to_sharp
Renamed
send_pc1403.cpp@0:07819bc70660, 2022-02-15 (annotated)
- Committer:
- ffxx68
- Date:
- Tue Feb 15 15:37:06 2022 +0000
- Revision:
- 0:07819bc70660
- Child:
- 1:9289febf4ae9
Communication with a Sharp PC (a Pocket Computer from the '80s)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ffxx68 | 0:07819bc70660 | 1 | #include "send_pc1403.h" |
ffxx68 | 0:07819bc70660 | 2 | #include "bit_send.h" |
ffxx68 | 0:07819bc70660 | 3 | |
ffxx68 | 0:07819bc70660 | 4 | /////////////////////////////////////////////////////// |
ffxx68 | 0:07819bc70660 | 5 | // mbed objects |
ffxx68 | 0:07819bc70660 | 6 | /* Timer bit_timer; |
ffxx68 | 0:07819bc70660 | 7 | */ |
ffxx68 | 0:07819bc70660 | 8 | |
ffxx68 | 0:07819bc70660 | 9 | // volatile force main to reread from SRAM |
ffxx68 | 0:07819bc70660 | 10 | // with the new contents the interrupt wrote to it |
ffxx68 | 0:07819bc70660 | 11 | // but, since both read/write there, this should be 'protected'! |
ffxx68 | 0:07819bc70660 | 12 | // https://os.mbed.com/questions/5146/Sharing-Variables-with-Interrupts/ |
ffxx68 | 0:07819bc70660 | 13 | volatile uint32_t bit_tick_flags; |
ffxx68 | 0:07819bc70660 | 14 | static uint8_t bit_tick_count; |
ffxx68 | 0:07819bc70660 | 15 | static uint8_t bit_cycle_count; |
ffxx68 | 0:07819bc70660 | 16 | static uint32_t bit_out_value; |
ffxx68 | 0:07819bc70660 | 17 | |
ffxx68 | 0:07819bc70660 | 18 | /////////////////////////////////////////////////////// |
ffxx68 | 0:07819bc70660 | 19 | // variables from PocketTools code |
ffxx68 | 0:07819bc70660 | 20 | uint SHCc = 0 , /* Read not from bin, but from Transfile PC plus SHC-format (header included) */ |
ffxx68 | 0:07819bc70660 | 21 | SHCe = 0 ; /* End marks are the SHC Basic image included only*/ |
ffxx68 | 0:07819bc70660 | 22 | uint QTc = 0 ; /* Write to Quick-Tape wave format */ |
ffxx68 | 0:07819bc70660 | 23 | uint STc = 0 ; /* Header of SuperTape or file header of PC-1600 format is in the image included */ |
ffxx68 | 0:07819bc70660 | 24 | uint TAPc = 0 ; /* Write not to wave format but to emulator tap format (raw bytes)*/ |
ffxx68 | 0:07819bc70660 | 25 | uint Qcnt = 0 ; /* Quiet, minimal output */ |
ffxx68 | 0:07819bc70660 | 26 | uint Scnt = 0 ; /* Number of sync parameters or sync and sync spaces was defined */ |
ffxx68 | 0:07819bc70660 | 27 | uint Acnt = 0 ; /* Number of address parameters, non standard load or entry addresses */ |
ffxx68 | 0:07819bc70660 | 28 | uint Mcnt = 0 ; /* Read header parameter from a file */ |
ffxx68 | 0:07819bc70660 | 29 | |
ffxx68 | 0:07819bc70660 | 30 | double speed = 1.00 ; /* Used it for modified Pocket Computer with a CPU Speed Up switched on */ |
ffxx68 | 0:07819bc70660 | 31 | |
ffxx68 | 0:07819bc70660 | 32 | ulong pcId = 1500 ; /* ID number of the pocket computer */ |
ffxx68 | 0:07819bc70660 | 33 | ushort pcgrpId = IDENT_UNKNOWN ; |
ffxx68 | 0:07819bc70660 | 34 | // ulong pcAddr = 0 ; /* PC-specific address, used for the end of variable data of PCs with DB-tables */ |
ffxx68 | 0:07819bc70660 | 35 | bool cnvstr_upr = false ; /* Convert strings to upper, for Pokecon with SML-key not */ |
ffxx68 | 0:07819bc70660 | 36 | bool type_asm = false ; /* Image contains assembler source code (subtype), true for CASL and CAP-X */ |
ffxx68 | 0:07819bc70660 | 37 | // TODO (mr#2#): Count all warnings and errors |
ffxx68 | 0:07819bc70660 | 38 | ulong err_cnt = 0 ; /* counts minor errors */ |
ffxx68 | 0:07819bc70660 | 39 | ulong wrn_cnt = 0 ; /* counts warnings */ |
ffxx68 | 0:07819bc70660 | 40 | |
ffxx68 | 0:07819bc70660 | 41 | |
ffxx68 | 0:07819bc70660 | 42 | /** replaced by the buffered |
ffxx68 | 0:07819bc70660 | 43 | int bitSend (uint8_t bit, uint8_t invert){ |
ffxx68 | 0:07819bc70660 | 44 | |
ffxx68 | 0:07819bc70660 | 45 | uint8_t cycle_n; |
ffxx68 | 0:07819bc70660 | 46 | uint32_t theor_time = 0; |
ffxx68 | 0:07819bc70660 | 47 | |
ffxx68 | 0:07819bc70660 | 48 | bit_timer.reset(); |
ffxx68 | 0:07819bc70660 | 49 | bit_timer.start(); |
ffxx68 | 0:07819bc70660 | 50 | switch (bit ^ invert) |
ffxx68 | 0:07819bc70660 | 51 | { |
ffxx68 | 0:07819bc70660 | 52 | case 0: |
ffxx68 | 0:07819bc70660 | 53 | for ( cycle_n = 0; cycle_n < BIT_0_NCYCLES; cycle_n++) { |
ffxx68 | 0:07819bc70660 | 54 | bit_out = 1; |
ffxx68 | 0:07819bc70660 | 55 | wait_us( BIT_0_DELAY_HIGH ); |
ffxx68 | 0:07819bc70660 | 56 | bit_out = 0; |
ffxx68 | 0:07819bc70660 | 57 | wait_us( BIT_0_DELAY_LOW ); |
ffxx68 | 0:07819bc70660 | 58 | } |
ffxx68 | 0:07819bc70660 | 59 | theor_time = ( BIT_0_DELAY_LOW + BIT_0_DELAY_HIGH) * BIT_0_NCYCLES; |
ffxx68 | 0:07819bc70660 | 60 | |
ffxx68 | 0:07819bc70660 | 61 | case 1: |
ffxx68 | 0:07819bc70660 | 62 | for ( cycle_n = 0; cycle_n < BIT_0_NCYCLES; cycle_n++) { |
ffxx68 | 0:07819bc70660 | 63 | bit_out = 1; |
ffxx68 | 0:07819bc70660 | 64 | wait_us( BIT_1_DELAY_HIGH ); |
ffxx68 | 0:07819bc70660 | 65 | bit_out = 0; |
ffxx68 | 0:07819bc70660 | 66 | wait_us( BIT_1_DELAY_LOW ); |
ffxx68 | 0:07819bc70660 | 67 | } |
ffxx68 | 0:07819bc70660 | 68 | theor_time = ( BIT_1_DELAY_LOW + BIT_1_DELAY_HIGH) * BIT_1_NCYCLES; |
ffxx68 | 0:07819bc70660 | 69 | } |
ffxx68 | 0:07819bc70660 | 70 | bit_timer.stop(); |
ffxx68 | 0:07819bc70660 | 71 | |
ffxx68 | 0:07819bc70660 | 72 | return (bit_timer.read_us() - theor_time); // difference real - theoretical timing (in us), per bit |
ffxx68 | 0:07819bc70660 | 73 | |
ffxx68 | 0:07819bc70660 | 74 | } |
ffxx68 | 0:07819bc70660 | 75 | */ |
ffxx68 | 0:07819bc70660 | 76 | |
ffxx68 | 0:07819bc70660 | 77 | //////////////////////////////////////////////////////////////////////////////// |
ffxx68 | 0:07819bc70660 | 78 | // WriteBitToWav replaced from PocketTools version (writing to a WAV file) |
ffxx68 | 0:07819bc70660 | 79 | // Here we send directly signals to OUT lines |
ffxx68 | 0:07819bc70660 | 80 | int WriteBitToWav (int value, |
ffxx68 | 0:07819bc70660 | 81 | FileInfo* ptrFile) |
ffxx68 | 0:07819bc70660 | 82 | { |
ffxx68 | 0:07819bc70660 | 83 | // Calling the buffered bit sending routine |
ffxx68 | 0:07819bc70660 | 84 | if ( bitWaitSend ( value, 0 ) > MAX_BIT_TIME_ERR ) |
ffxx68 | 0:07819bc70660 | 85 | return ( ERR_NOK ) ; |
ffxx68 | 0:07819bc70660 | 86 | else |
ffxx68 | 0:07819bc70660 | 87 | return ( ERR_OK ) ; |
ffxx68 | 0:07819bc70660 | 88 | } |
ffxx68 | 0:07819bc70660 | 89 | |
ffxx68 | 0:07819bc70660 | 90 | //////////////////////////////////////////////////////////////////////////////// |
ffxx68 | 0:07819bc70660 | 91 | // Write* methods taken from Pocket-Tools source code |
ffxx68 | 0:07819bc70660 | 92 | // https://www.peil-partner.de/ifhe.de/sharp/ |
ffxx68 | 0:07819bc70660 | 93 | int WriteQuaterToWav (uint value, |
ffxx68 | 0:07819bc70660 | 94 | uint stopBits, |
ffxx68 | 0:07819bc70660 | 95 | FileInfo* ptrFile) |
ffxx68 | 0:07819bc70660 | 96 | { |
ffxx68 | 0:07819bc70660 | 97 | uint tmp ; |
ffxx68 | 0:07819bc70660 | 98 | uint ii ; |
ffxx68 | 0:07819bc70660 | 99 | int error ; |
ffxx68 | 0:07819bc70660 | 100 | |
ffxx68 | 0:07819bc70660 | 101 | // if (TAPc > 0) return (WriteQuaterToTap (value, ptrFile)); // no |
ffxx68 | 0:07819bc70660 | 102 | |
ffxx68 | 0:07819bc70660 | 103 | do { |
ffxx68 | 0:07819bc70660 | 104 | error = WriteBitToWav (0, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 105 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 106 | |
ffxx68 | 0:07819bc70660 | 107 | for ( ii = 0 ; ii < 4 ; ++ii ) { |
ffxx68 | 0:07819bc70660 | 108 | tmp = 1 << ii ; |
ffxx68 | 0:07819bc70660 | 109 | if ( (value & tmp) == 0 ) |
ffxx68 | 0:07819bc70660 | 110 | error = WriteBitToWav (0, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 111 | else |
ffxx68 | 0:07819bc70660 | 112 | error = WriteBitToWav (1, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 113 | |
ffxx68 | 0:07819bc70660 | 114 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 115 | } |
ffxx68 | 0:07819bc70660 | 116 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 117 | |
ffxx68 | 0:07819bc70660 | 118 | for ( ii = 0 ; ii < stopBits ; ++ii ) { |
ffxx68 | 0:07819bc70660 | 119 | error = WriteBitToWav (1, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 120 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 121 | } |
ffxx68 | 0:07819bc70660 | 122 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 123 | |
ffxx68 | 0:07819bc70660 | 124 | } while (0) ; |
ffxx68 | 0:07819bc70660 | 125 | return (error); |
ffxx68 | 0:07819bc70660 | 126 | } |
ffxx68 | 0:07819bc70660 | 127 | |
ffxx68 | 0:07819bc70660 | 128 | int WriteByteToWav (ulong value, |
ffxx68 | 0:07819bc70660 | 129 | uchar order, |
ffxx68 | 0:07819bc70660 | 130 | uchar mode, |
ffxx68 | 0:07819bc70660 | 131 | FileInfo* ptrFile) |
ffxx68 | 0:07819bc70660 | 132 | { |
ffxx68 | 0:07819bc70660 | 133 | uint lsq ; |
ffxx68 | 0:07819bc70660 | 134 | uint msq ; |
ffxx68 | 0:07819bc70660 | 135 | int error ; |
ffxx68 | 0:07819bc70660 | 136 | |
ffxx68 | 0:07819bc70660 | 137 | // if (TAPc > 0) return (WriteByteToTap (value, order, ptrFile)) ; // no |
ffxx68 | 0:07819bc70660 | 138 | |
ffxx68 | 0:07819bc70660 | 139 | // if (order == ORDER_E) return (WriteByteToEWav (value, ptrFile)) ; // no 1403 |
ffxx68 | 0:07819bc70660 | 140 | |
ffxx68 | 0:07819bc70660 | 141 | do { |
ffxx68 | 0:07819bc70660 | 142 | lsq = value & 0x0F ; |
ffxx68 | 0:07819bc70660 | 143 | msq = (value >> 4) & 0x0F ; |
ffxx68 | 0:07819bc70660 | 144 | if (order == ORDER_INV) { |
ffxx68 | 0:07819bc70660 | 145 | error = WriteQuaterToWav (lsq, Mode[mode].stopb1, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 146 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 147 | error = WriteQuaterToWav (msq, Mode[mode].stopb2, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 148 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 149 | } |
ffxx68 | 0:07819bc70660 | 150 | else { |
ffxx68 | 0:07819bc70660 | 151 | error = WriteQuaterToWav (msq, Mode[mode].stopb1, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 152 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 153 | error = WriteQuaterToWav (lsq, Mode[mode].stopb2, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 154 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 155 | } |
ffxx68 | 0:07819bc70660 | 156 | |
ffxx68 | 0:07819bc70660 | 157 | } while (0) ; |
ffxx68 | 0:07819bc70660 | 158 | return (error); |
ffxx68 | 0:07819bc70660 | 159 | } |
ffxx68 | 0:07819bc70660 | 160 | |
ffxx68 | 0:07819bc70660 | 161 | int CheckSumB1 ( ulong Byte, |
ffxx68 | 0:07819bc70660 | 162 | FileInfo* ptrFile) |
ffxx68 | 0:07819bc70660 | 163 | { |
ffxx68 | 0:07819bc70660 | 164 | ushort sum ; |
ffxx68 | 0:07819bc70660 | 165 | |
ffxx68 | 0:07819bc70660 | 166 | /* Update the checksum */ |
ffxx68 | 0:07819bc70660 | 167 | sum = ptrFile->sum + ((Byte & 0xF0) >> 4) ; |
ffxx68 | 0:07819bc70660 | 168 | if (sum > 0xFF) { |
ffxx68 | 0:07819bc70660 | 169 | ++sum ; |
ffxx68 | 0:07819bc70660 | 170 | sum &= 0xFF ; |
ffxx68 | 0:07819bc70660 | 171 | } |
ffxx68 | 0:07819bc70660 | 172 | ptrFile->sum = (sum + (Byte & 0x0F)) & 0xFF ; |
ffxx68 | 0:07819bc70660 | 173 | |
ffxx68 | 0:07819bc70660 | 174 | return (0); |
ffxx68 | 0:07819bc70660 | 175 | } |
ffxx68 | 0:07819bc70660 | 176 | |
ffxx68 | 0:07819bc70660 | 177 | |
ffxx68 | 0:07819bc70660 | 178 | int CheckSumE ( ulong Byte, |
ffxx68 | 0:07819bc70660 | 179 | // ulong* ptrSum ) |
ffxx68 | 0:07819bc70660 | 180 | FileInfo* ptrFile) |
ffxx68 | 0:07819bc70660 | 181 | { |
ffxx68 | 0:07819bc70660 | 182 | uint tmp, ii ; |
ffxx68 | 0:07819bc70660 | 183 | |
ffxx68 | 0:07819bc70660 | 184 | /* Update the checksum */ |
ffxx68 | 0:07819bc70660 | 185 | tmp = 0x80 ; |
ffxx68 | 0:07819bc70660 | 186 | for ( ii = 0 ; ii < 8 ; ++ii, tmp >>= 1 ) |
ffxx68 | 0:07819bc70660 | 187 | if ( (Byte & tmp) != 0 ) |
ffxx68 | 0:07819bc70660 | 188 | // ++ *ptrSum ; |
ffxx68 | 0:07819bc70660 | 189 | ++ ptrFile->sum ; |
ffxx68 | 0:07819bc70660 | 190 | |
ffxx68 | 0:07819bc70660 | 191 | return (0); |
ffxx68 | 0:07819bc70660 | 192 | } |
ffxx68 | 0:07819bc70660 | 193 | |
ffxx68 | 0:07819bc70660 | 194 | int WriteByteSumToWav (ulong value, |
ffxx68 | 0:07819bc70660 | 195 | uchar order, |
ffxx68 | 0:07819bc70660 | 196 | uchar mode, |
ffxx68 | 0:07819bc70660 | 197 | FileInfo* ptrFile) |
ffxx68 | 0:07819bc70660 | 198 | { |
ffxx68 | 0:07819bc70660 | 199 | int error; |
ffxx68 | 0:07819bc70660 | 200 | |
ffxx68 | 0:07819bc70660 | 201 | // ... |
ffxx68 | 0:07819bc70660 | 202 | |
ffxx68 | 0:07819bc70660 | 203 | error = WriteByteToWav (value, order, mode, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 204 | |
ffxx68 | 0:07819bc70660 | 205 | if (mode == MODE_B22) ptrFile->sum += value ; |
ffxx68 | 0:07819bc70660 | 206 | else if (mode == MODE_B9) CheckSumE (value, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 207 | else CheckSumB1 (value, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 208 | |
ffxx68 | 0:07819bc70660 | 209 | ++ptrFile->count ; |
ffxx68 | 0:07819bc70660 | 210 | ++ptrFile->total ; |
ffxx68 | 0:07819bc70660 | 211 | |
ffxx68 | 0:07819bc70660 | 212 | switch (mode) { |
ffxx68 | 0:07819bc70660 | 213 | // ... |
ffxx68 | 0:07819bc70660 | 214 | case MODE_B14 : |
ffxx68 | 0:07819bc70660 | 215 | case MODE_B13 : |
ffxx68 | 0:07819bc70660 | 216 | if ( ptrFile->count >= BLK_NEW) { |
ffxx68 | 0:07819bc70660 | 217 | |
ffxx68 | 0:07819bc70660 | 218 | if ( (ptrFile->debug & 0x0040) > 0 ) |
ffxx68 | 0:07819bc70660 | 219 | printf(" (%02X)", (uchar) ptrFile->sum); |
ffxx68 | 0:07819bc70660 | 220 | |
ffxx68 | 0:07819bc70660 | 221 | /* Write the checksum */ |
ffxx68 | 0:07819bc70660 | 222 | error = WriteByteToWav (ptrFile->sum, order, mode, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 223 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 224 | |
ffxx68 | 0:07819bc70660 | 225 | ptrFile->count = 0 ; |
ffxx68 | 0:07819bc70660 | 226 | ptrFile->sum = 0 ; |
ffxx68 | 0:07819bc70660 | 227 | } |
ffxx68 | 0:07819bc70660 | 228 | break ; |
ffxx68 | 0:07819bc70660 | 229 | default : |
ffxx68 | 0:07819bc70660 | 230 | // printf ("%s: Unknown Mode\n", argP) ; |
ffxx68 | 0:07819bc70660 | 231 | break ; |
ffxx68 | 0:07819bc70660 | 232 | } |
ffxx68 | 0:07819bc70660 | 233 | return (error); |
ffxx68 | 0:07819bc70660 | 234 | |
ffxx68 | 0:07819bc70660 | 235 | } |
ffxx68 | 0:07819bc70660 | 236 | |
ffxx68 | 0:07819bc70660 | 237 | int WriteSyncToWav (ulong nbSync, // |
ffxx68 | 0:07819bc70660 | 238 | FileInfo* ptrFile) |
ffxx68 | 0:07819bc70660 | 239 | { |
ffxx68 | 0:07819bc70660 | 240 | ulong ii ; |
ffxx68 | 0:07819bc70660 | 241 | int error = ERR_OK ; |
ffxx68 | 0:07819bc70660 | 242 | |
ffxx68 | 0:07819bc70660 | 243 | if (TAPc > 0) return (ERR_OK); // no |
ffxx68 | 0:07819bc70660 | 244 | |
ffxx68 | 0:07819bc70660 | 245 | do { |
ffxx68 | 0:07819bc70660 | 246 | /* Write the Synchro patern */ |
ffxx68 | 0:07819bc70660 | 247 | for ( ii = 0 ; ii < nbSync ; ++ii ) { |
ffxx68 | 0:07819bc70660 | 248 | error = WriteBitToWav (1, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 249 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 250 | } |
ffxx68 | 0:07819bc70660 | 251 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 252 | |
ffxx68 | 0:07819bc70660 | 253 | } while (0) ; |
ffxx68 | 0:07819bc70660 | 254 | return (error); |
ffxx68 | 0:07819bc70660 | 255 | } |
ffxx68 | 0:07819bc70660 | 256 | |
ffxx68 | 0:07819bc70660 | 257 | ulong SwapByte (ulong byte) |
ffxx68 | 0:07819bc70660 | 258 | { |
ffxx68 | 0:07819bc70660 | 259 | return ( (byte >> 4) + (byte << 4 & 0xF0) ); |
ffxx68 | 0:07819bc70660 | 260 | } |
ffxx68 | 0:07819bc70660 | 261 | |
ffxx68 | 0:07819bc70660 | 262 | /* File name for New and Old BASIC */ |
ffxx68 | 0:07819bc70660 | 263 | int WriteSaveNameToWav (char* ptrName, |
ffxx68 | 0:07819bc70660 | 264 | uchar mode, |
ffxx68 | 0:07819bc70660 | 265 | FileInfo* ptrFile) |
ffxx68 | 0:07819bc70660 | 266 | { |
ffxx68 | 0:07819bc70660 | 267 | uint ii ; |
ffxx68 | 0:07819bc70660 | 268 | uint tmpL ; |
ffxx68 | 0:07819bc70660 | 269 | char byte ; |
ffxx68 | 0:07819bc70660 | 270 | char tmpS[20] ; |
ffxx68 | 0:07819bc70660 | 271 | int error ; |
ffxx68 | 0:07819bc70660 | 272 | |
ffxx68 | 0:07819bc70660 | 273 | if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG ptrName %s\n\r", ptrName); |
ffxx68 | 0:07819bc70660 | 274 | |
ffxx68 | 0:07819bc70660 | 275 | do { |
ffxx68 | 0:07819bc70660 | 276 | /* Uppercase the name is done in main if needed */ |
ffxx68 | 0:07819bc70660 | 277 | // tmpL = strlen (ptrName) ; |
ffxx68 | 0:07819bc70660 | 278 | for (ii = 0; ii < cLPF-1 && ptrName[ii] != '\0'; ii++) ; |
ffxx68 | 0:07819bc70660 | 279 | tmpL = ii; |
ffxx68 | 0:07819bc70660 | 280 | |
ffxx68 | 0:07819bc70660 | 281 | if (tmpL > 7) |
ffxx68 | 0:07819bc70660 | 282 | tmpL = 7 ; |
ffxx68 | 0:07819bc70660 | 283 | |
ffxx68 | 0:07819bc70660 | 284 | for ( ii = 0 ; ii < tmpL ; ++ii ) |
ffxx68 | 0:07819bc70660 | 285 | tmpS[ii] = ptrName[ii] ; |
ffxx68 | 0:07819bc70660 | 286 | |
ffxx68 | 0:07819bc70660 | 287 | tmpS[tmpL] = 0 ; |
ffxx68 | 0:07819bc70660 | 288 | //if (Qcnt == 0) printf ("Save name : %s\n", tmpS) ; |
ffxx68 | 0:07819bc70660 | 289 | // strncpy( ptrName, tmpS, cLPF-1) ; |
ffxx68 | 0:07819bc70660 | 290 | for (ii = 0; ii < cLPF-1 && ptrName[ii] != '\0'; ii++) |
ffxx68 | 0:07819bc70660 | 291 | tmpS[ii] = ptrName[ii]; |
ffxx68 | 0:07819bc70660 | 292 | /* crash? |
ffxx68 | 0:07819bc70660 | 293 | for ( ; ii < cLPF-1; ii++) |
ffxx68 | 0:07819bc70660 | 294 | tmpS[ii] = '\0'; |
ffxx68 | 0:07819bc70660 | 295 | */ |
ffxx68 | 0:07819bc70660 | 296 | tmpL = 7 - tmpL ; |
ffxx68 | 0:07819bc70660 | 297 | for ( ii = 0 ; ii < tmpL ; ++ii ) |
ffxx68 | 0:07819bc70660 | 298 | tmpS[ii] = 0 ; |
ffxx68 | 0:07819bc70660 | 299 | |
ffxx68 | 0:07819bc70660 | 300 | if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG tmpS %s\n\r", tmpS); |
ffxx68 | 0:07819bc70660 | 301 | for ( ii = tmpL ; ii < 7 ; ++ii ) { |
ffxx68 | 0:07819bc70660 | 302 | byte = (ulong) ptrName[6 - ii] ; |
ffxx68 | 0:07819bc70660 | 303 | |
ffxx68 | 0:07819bc70660 | 304 | switch (mode) { |
ffxx68 | 0:07819bc70660 | 305 | case MODE_B19 : |
ffxx68 | 0:07819bc70660 | 306 | case MODE_B20 : |
ffxx68 | 0:07819bc70660 | 307 | |
ffxx68 | 0:07819bc70660 | 308 | if (byte < 0x80) |
ffxx68 | 0:07819bc70660 | 309 | byte = CodeOld[byte] ; |
ffxx68 | 0:07819bc70660 | 310 | else |
ffxx68 | 0:07819bc70660 | 311 | byte = CodeOld[0] ; |
ffxx68 | 0:07819bc70660 | 312 | break ; |
ffxx68 | 0:07819bc70660 | 313 | |
ffxx68 | 0:07819bc70660 | 314 | default : |
ffxx68 | 0:07819bc70660 | 315 | |
ffxx68 | 0:07819bc70660 | 316 | if (byte >= 0x80) |
ffxx68 | 0:07819bc70660 | 317 | byte = 0x20 ; |
ffxx68 | 0:07819bc70660 | 318 | break ; |
ffxx68 | 0:07819bc70660 | 319 | } |
ffxx68 | 0:07819bc70660 | 320 | tmpS[ii] = (char) SwapByte(byte) ; |
ffxx68 | 0:07819bc70660 | 321 | } |
ffxx68 | 0:07819bc70660 | 322 | tmpS[7] = 0x5F ; |
ffxx68 | 0:07819bc70660 | 323 | |
ffxx68 | 0:07819bc70660 | 324 | /* Write the Name */ |
ffxx68 | 0:07819bc70660 | 325 | ptrFile->count = 0 ; |
ffxx68 | 0:07819bc70660 | 326 | ptrFile->sum = 0 ; |
ffxx68 | 0:07819bc70660 | 327 | for ( ii = 0 ; ii < 8 ; ++ii ) { |
ffxx68 | 0:07819bc70660 | 328 | error = WriteByteSumToWav (tmpS[ii], ORDER_STD, mode, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 329 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 330 | } |
ffxx68 | 0:07819bc70660 | 331 | |
ffxx68 | 0:07819bc70660 | 332 | if (ptrFile->ident == IDENT_PC1211) |
ffxx68 | 0:07819bc70660 | 333 | error = WriteSyncToWav (151, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 334 | else if (ptrFile->ident == IDENT_PC121_DAT) |
ffxx68 | 0:07819bc70660 | 335 | error = WriteSyncToWav (111, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 336 | |
ffxx68 | 0:07819bc70660 | 337 | ptrFile->count = 0 ; |
ffxx68 | 0:07819bc70660 | 338 | ptrFile->sum = 0 ; |
ffxx68 | 0:07819bc70660 | 339 | |
ffxx68 | 0:07819bc70660 | 340 | } while (0) ; |
ffxx68 | 0:07819bc70660 | 341 | return (error); |
ffxx68 | 0:07819bc70660 | 342 | } |
ffxx68 | 0:07819bc70660 | 343 | |
ffxx68 | 0:07819bc70660 | 344 | int DEBUGSaveNameToWav (char* ptrName, |
ffxx68 | 0:07819bc70660 | 345 | uchar mode, |
ffxx68 | 0:07819bc70660 | 346 | FileInfo* ptrFile) |
ffxx68 | 0:07819bc70660 | 347 | { |
ffxx68 | 0:07819bc70660 | 348 | uint ii ; |
ffxx68 | 0:07819bc70660 | 349 | uint i ; |
ffxx68 | 0:07819bc70660 | 350 | ulong byte ; |
ffxx68 | 0:07819bc70660 | 351 | ulong tmpL ; |
ffxx68 | 0:07819bc70660 | 352 | char tmpS[10] ; |
ffxx68 | 0:07819bc70660 | 353 | int error ; |
ffxx68 | 0:07819bc70660 | 354 | |
ffxx68 | 0:07819bc70660 | 355 | do { |
ffxx68 | 0:07819bc70660 | 356 | /* Uppercase the name is done in main if needed */ |
ffxx68 | 0:07819bc70660 | 357 | tmpL = strlen (ptrName) ; |
ffxx68 | 0:07819bc70660 | 358 | printf("DEBUG tmpL %u\n\r", tmpL); |
ffxx68 | 0:07819bc70660 | 359 | |
ffxx68 | 0:07819bc70660 | 360 | if (tmpL > 7) |
ffxx68 | 0:07819bc70660 | 361 | tmpL = 7 ; |
ffxx68 | 0:07819bc70660 | 362 | |
ffxx68 | 0:07819bc70660 | 363 | for ( ii = 0 ; ii < tmpL ; ++ii ) { |
ffxx68 | 0:07819bc70660 | 364 | printf("DEBUG ptrName[ii] %c\n\r", ptrName[ii]); |
ffxx68 | 0:07819bc70660 | 365 | tmpS[ii] = ptrName[ii] ; |
ffxx68 | 0:07819bc70660 | 366 | } |
ffxx68 | 0:07819bc70660 | 367 | tmpS[tmpL] = 0 ; |
ffxx68 | 0:07819bc70660 | 368 | //if (Qcnt == 0) printf ("Save name : %s\n", tmpS) ; |
ffxx68 | 0:07819bc70660 | 369 | printf("DEBUG ptrName %s\n\r", ptrName); |
ffxx68 | 0:07819bc70660 | 370 | printf("DEBUG i 1 "); |
ffxx68 | 0:07819bc70660 | 371 | |
ffxx68 | 0:07819bc70660 | 372 | // strncpy( ptrName, tmpS, cLPF-1) ; |
ffxx68 | 0:07819bc70660 | 373 | for (i = 0; i < cLPF-1 && ptrName[i] != '\0'; i++) { |
ffxx68 | 0:07819bc70660 | 374 | printf("%u ", i); |
ffxx68 | 0:07819bc70660 | 375 | tmpS[i] = ptrName[i]; |
ffxx68 | 0:07819bc70660 | 376 | } |
ffxx68 | 0:07819bc70660 | 377 | printf("\n\rDEBUG i 2 "); |
ffxx68 | 0:07819bc70660 | 378 | /* crash? |
ffxx68 | 0:07819bc70660 | 379 | for ( ; i < cLPF-1; i++) { |
ffxx68 | 0:07819bc70660 | 380 | printf("%u ", i); |
ffxx68 | 0:07819bc70660 | 381 | tmpS[i] = '\0'; |
ffxx68 | 0:07819bc70660 | 382 | } |
ffxx68 | 0:07819bc70660 | 383 | */ |
ffxx68 | 0:07819bc70660 | 384 | printf("\n\rDEBUG tmpS %s\n\r", tmpS); |
ffxx68 | 0:07819bc70660 | 385 | tmpL = 7 - tmpL ; |
ffxx68 | 0:07819bc70660 | 386 | for ( ii = 0 ; ii < tmpL ; ++ii ) |
ffxx68 | 0:07819bc70660 | 387 | tmpS[ii] = 0 ; |
ffxx68 | 0:07819bc70660 | 388 | printf("DEBUG tmpS %s\n\r", tmpS); |
ffxx68 | 0:07819bc70660 | 389 | |
ffxx68 | 0:07819bc70660 | 390 | /* reverse-order bytes */ |
ffxx68 | 0:07819bc70660 | 391 | for ( ii = tmpL ; ii < 7 ; ++ii ) { |
ffxx68 | 0:07819bc70660 | 392 | byte = (ulong) ptrName[6 - ii] ; |
ffxx68 | 0:07819bc70660 | 393 | printf("DEBUG byte %u\n\r", byte); |
ffxx68 | 0:07819bc70660 | 394 | |
ffxx68 | 0:07819bc70660 | 395 | switch (mode) { |
ffxx68 | 0:07819bc70660 | 396 | case MODE_B19 : |
ffxx68 | 0:07819bc70660 | 397 | case MODE_B20 : |
ffxx68 | 0:07819bc70660 | 398 | |
ffxx68 | 0:07819bc70660 | 399 | if (byte < 0x80) |
ffxx68 | 0:07819bc70660 | 400 | byte = CodeOld[byte] ; |
ffxx68 | 0:07819bc70660 | 401 | else |
ffxx68 | 0:07819bc70660 | 402 | byte = CodeOld[0] ; |
ffxx68 | 0:07819bc70660 | 403 | break ; |
ffxx68 | 0:07819bc70660 | 404 | |
ffxx68 | 0:07819bc70660 | 405 | default : |
ffxx68 | 0:07819bc70660 | 406 | |
ffxx68 | 0:07819bc70660 | 407 | if (byte >= 0x80) |
ffxx68 | 0:07819bc70660 | 408 | byte = 0x20 ; |
ffxx68 | 0:07819bc70660 | 409 | break ; |
ffxx68 | 0:07819bc70660 | 410 | } |
ffxx68 | 0:07819bc70660 | 411 | tmpS[ii] = (char) SwapByte(byte) ; |
ffxx68 | 0:07819bc70660 | 412 | } |
ffxx68 | 0:07819bc70660 | 413 | tmpS[7] = 0x5F ; |
ffxx68 | 0:07819bc70660 | 414 | printf("DEBUG ii %u\n\r", ii); |
ffxx68 | 0:07819bc70660 | 415 | |
ffxx68 | 0:07819bc70660 | 416 | /* Write the Name */ |
ffxx68 | 0:07819bc70660 | 417 | ptrFile->count = 0 ; |
ffxx68 | 0:07819bc70660 | 418 | ptrFile->sum = 0 ; |
ffxx68 | 0:07819bc70660 | 419 | for ( ii = 0 ; ii < 8 ; ++ii ) { |
ffxx68 | 0:07819bc70660 | 420 | error = WriteByteSumToWav (tmpS[ii], ORDER_STD, mode, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 421 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 422 | } |
ffxx68 | 0:07819bc70660 | 423 | if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG Name - Bytes was printed swapped.\n\r"); |
ffxx68 | 0:07819bc70660 | 424 | |
ffxx68 | 0:07819bc70660 | 425 | printf("DEBUG WriteSyncToWav prima\n\r"); |
ffxx68 | 0:07819bc70660 | 426 | |
ffxx68 | 0:07819bc70660 | 427 | if (ptrFile->ident == IDENT_PC1211) |
ffxx68 | 0:07819bc70660 | 428 | error = WriteSyncToWav (151, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 429 | else if (ptrFile->ident == IDENT_PC121_DAT) |
ffxx68 | 0:07819bc70660 | 430 | error = WriteSyncToWav (111, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 431 | printf("DEBUG WriteSyncToWav dopo\n\r"); |
ffxx68 | 0:07819bc70660 | 432 | |
ffxx68 | 0:07819bc70660 | 433 | ptrFile->count = 0 ; |
ffxx68 | 0:07819bc70660 | 434 | ptrFile->sum = 0 ; |
ffxx68 | 0:07819bc70660 | 435 | printf("DEBUG fine\n\r"); |
ffxx68 | 0:07819bc70660 | 436 | |
ffxx68 | 0:07819bc70660 | 437 | } while (0) ; |
ffxx68 | 0:07819bc70660 | 438 | return (error); |
ffxx68 | 0:07819bc70660 | 439 | } |
ffxx68 | 0:07819bc70660 | 440 | |
ffxx68 | 0:07819bc70660 | 441 | /* Head of Binary Data for New and Old series */ |
ffxx68 | 0:07819bc70660 | 442 | int WriteHeadToBinWav (ulong addr, |
ffxx68 | 0:07819bc70660 | 443 | ulong size, |
ffxx68 | 0:07819bc70660 | 444 | uchar mode, |
ffxx68 | 0:07819bc70660 | 445 | FileInfo* ptrFile) |
ffxx68 | 0:07819bc70660 | 446 | { |
ffxx68 | 0:07819bc70660 | 447 | int ii ; |
ffxx68 | 0:07819bc70660 | 448 | ulong len ; |
ffxx68 | 0:07819bc70660 | 449 | ulong tmpL ; |
ffxx68 | 0:07819bc70660 | 450 | int error ; |
ffxx68 | 0:07819bc70660 | 451 | |
ffxx68 | 0:07819bc70660 | 452 | do { |
ffxx68 | 0:07819bc70660 | 453 | /* if (Qcnt == 0) |
ffxx68 | 0:07819bc70660 | 454 | { |
ffxx68 | 0:07819bc70660 | 455 | printf ("Start Address: 0x%04X\n", (uint) addr); |
ffxx68 | 0:07819bc70660 | 456 | printf ("End Address: 0x%04X, Length: %d bytes\n", (uint) (addr + size -1), (uint) size); |
ffxx68 | 0:07819bc70660 | 457 | } |
ffxx68 | 0:07819bc70660 | 458 | */ |
ffxx68 | 0:07819bc70660 | 459 | |
ffxx68 | 0:07819bc70660 | 460 | ptrFile->count = 0 ; |
ffxx68 | 0:07819bc70660 | 461 | ptrFile->sum = 0 ; |
ffxx68 | 0:07819bc70660 | 462 | for ( ii = 0 ; ii < 4 ; ++ii ) { |
ffxx68 | 0:07819bc70660 | 463 | error = WriteByteSumToWav (0, ORDER_STD, mode, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 464 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 465 | } |
ffxx68 | 0:07819bc70660 | 466 | |
ffxx68 | 0:07819bc70660 | 467 | /* Write the address, this method is necessary because of swapped checksums in the header. */ |
ffxx68 | 0:07819bc70660 | 468 | tmpL = ((addr >> 4) & 0xF0) + (addr >> 12) ; /* H swapped */ |
ffxx68 | 0:07819bc70660 | 469 | error = WriteByteSumToWav (tmpL, ORDER_STD, mode, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 470 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 471 | |
ffxx68 | 0:07819bc70660 | 472 | tmpL = ((addr << 4) & 0xF0) + ((addr >> 4) & 0x0F) ;/* L swapped */ |
ffxx68 | 0:07819bc70660 | 473 | error = WriteByteSumToWav (tmpL, ORDER_STD, mode, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 474 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 475 | |
ffxx68 | 0:07819bc70660 | 476 | /* Write the Length */ |
ffxx68 | 0:07819bc70660 | 477 | len = size - 1 ; |
ffxx68 | 0:07819bc70660 | 478 | tmpL = ((len >> 4) & 0xF0) + (len >> 12) ; |
ffxx68 | 0:07819bc70660 | 479 | error = WriteByteSumToWav (tmpL, ORDER_STD, mode, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 480 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 481 | |
ffxx68 | 0:07819bc70660 | 482 | tmpL = ((len << 4) & 0xF0) + ((len >> 4) & 0x0F) ; |
ffxx68 | 0:07819bc70660 | 483 | error = WriteByteSumToWav (tmpL, ORDER_STD, mode, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 484 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 485 | |
ffxx68 | 0:07819bc70660 | 486 | ptrFile->count = 0 ; |
ffxx68 | 0:07819bc70660 | 487 | ptrFile->sum = 0 ; |
ffxx68 | 0:07819bc70660 | 488 | |
ffxx68 | 0:07819bc70660 | 489 | } while (0) ; |
ffxx68 | 0:07819bc70660 | 490 | return (error); |
ffxx68 | 0:07819bc70660 | 491 | } |
ffxx68 | 0:07819bc70660 | 492 | |
ffxx68 | 0:07819bc70660 | 493 | int WriteFooterToNewWav (FileInfo* ptrFile) |
ffxx68 | 0:07819bc70660 | 494 | { |
ffxx68 | 0:07819bc70660 | 495 | int error ; |
ffxx68 | 0:07819bc70660 | 496 | |
ffxx68 | 0:07819bc70660 | 497 | do { |
ffxx68 | 0:07819bc70660 | 498 | ptrFile->count = 0 ; /* no checksum writing from here until the end */ |
ffxx68 | 0:07819bc70660 | 499 | |
ffxx68 | 0:07819bc70660 | 500 | error = WriteByteSumToWav(BAS_NEW_EOF, ORDER_STD, ptrFile->mode, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 501 | // error = WriteByteSumToB13Wav (BAS_NEW_EOF, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 502 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 503 | |
ffxx68 | 0:07819bc70660 | 504 | error = WriteByteToWav(BAS_NEW_EOF, ORDER_STD, ptrFile->mode, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 505 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 506 | |
ffxx68 | 0:07819bc70660 | 507 | if ( (ptrFile->debug & 0x00C0) > 0 ) |
ffxx68 | 0:07819bc70660 | 508 | printf(" EOF:%02X", (uchar) BAS_NEW_EOF); |
ffxx68 | 0:07819bc70660 | 509 | |
ffxx68 | 0:07819bc70660 | 510 | error = WriteByteToWav(ptrFile->sum, ORDER_STD, ptrFile->mode, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 511 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 512 | |
ffxx68 | 0:07819bc70660 | 513 | if ( (ptrFile->debug & 0x0040) > 0 ) |
ffxx68 | 0:07819bc70660 | 514 | printf(" (%02X)", (uchar) ptrFile->sum); |
ffxx68 | 0:07819bc70660 | 515 | |
ffxx68 | 0:07819bc70660 | 516 | /* there are 2bits more HIGH at the end of transmission (at least for PC-1402) M. NOSSWITZ */ |
ffxx68 | 0:07819bc70660 | 517 | |
ffxx68 | 0:07819bc70660 | 518 | error = WriteBitToWav (1, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 519 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 520 | |
ffxx68 | 0:07819bc70660 | 521 | error = WriteBitToWav (1, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 522 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 523 | |
ffxx68 | 0:07819bc70660 | 524 | /* This puts 2 bits of silence (or 2 HIGH bits alternatively) to the end of the wave file. */ |
ffxx68 | 0:07819bc70660 | 525 | /* CLOAD does not accept any sound, that could be interpreted as a start bit, */ |
ffxx68 | 0:07819bc70660 | 526 | /* during post-processing. Original CSAVE switches the signal low ms after the */ |
ffxx68 | 0:07819bc70660 | 527 | /* end of transmission, before the motor of the cassette recorder is switched off. */ |
ffxx68 | 0:07819bc70660 | 528 | /* This level out is visible in the CSAVE audio signal after the last bit. T. Muecker */ |
ffxx68 | 0:07819bc70660 | 529 | |
ffxx68 | 0:07819bc70660 | 530 | error = WriteBitToWav (3, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 531 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 532 | |
ffxx68 | 0:07819bc70660 | 533 | error = WriteBitToWav (2, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 534 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 535 | |
ffxx68 | 0:07819bc70660 | 536 | } while (0) ; |
ffxx68 | 0:07819bc70660 | 537 | return (error); |
ffxx68 | 0:07819bc70660 | 538 | } |
ffxx68 | 0:07819bc70660 | 539 | |
ffxx68 | 0:07819bc70660 | 540 | int WriteFooterToMemoWav (FileInfo* ptrFile) |
ffxx68 | 0:07819bc70660 | 541 | { |
ffxx68 | 0:07819bc70660 | 542 | int error ; |
ffxx68 | 0:07819bc70660 | 543 | |
ffxx68 | 0:07819bc70660 | 544 | do { |
ffxx68 | 0:07819bc70660 | 545 | error = WriteByteToWav(ptrFile->sum, ORDER_STD, ptrFile->mode, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 546 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 547 | |
ffxx68 | 0:07819bc70660 | 548 | if ( (ptrFile->debug & 0x0040) > 0 ) |
ffxx68 | 0:07819bc70660 | 549 | printf(" (%02X)", (uchar) ptrFile->sum); |
ffxx68 | 0:07819bc70660 | 550 | |
ffxx68 | 0:07819bc70660 | 551 | error = WriteBitToWav (1, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 552 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 553 | |
ffxx68 | 0:07819bc70660 | 554 | error = WriteBitToWav (1, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 555 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 556 | |
ffxx68 | 0:07819bc70660 | 557 | /* This puts 2 bits of silence (or 2 HIGH bits alternatively) to the end of the wave file. */ |
ffxx68 | 0:07819bc70660 | 558 | |
ffxx68 | 0:07819bc70660 | 559 | error = WriteBitToWav (3, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 560 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 561 | |
ffxx68 | 0:07819bc70660 | 562 | error = WriteBitToWav (2, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 563 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 564 | |
ffxx68 | 0:07819bc70660 | 565 | } while (0) ; |
ffxx68 | 0:07819bc70660 | 566 | return (error); |
ffxx68 | 0:07819bc70660 | 567 | } |
ffxx68 | 0:07819bc70660 | 568 | |
ffxx68 | 0:07819bc70660 | 569 | ///////////////////////////////////////////////////////////////////////////// |
ffxx68 | 0:07819bc70660 | 570 | // My file-send implementation |
ffxx68 | 0:07819bc70660 | 571 | // Inspired to Pocket-Tools source code ... |
ffxx68 | 0:07819bc70660 | 572 | int FileSend ( char* FileName, char* FileStream, uint FileSize, FileInfo* ptrFile ) |
ffxx68 | 0:07819bc70660 | 573 | { |
ffxx68 | 0:07819bc70660 | 574 | int pcId = PC_ID; |
ffxx68 | 0:07819bc70660 | 575 | uchar type ; |
ffxx68 | 0:07819bc70660 | 576 | |
ffxx68 | 0:07819bc70660 | 577 | uint32_t ii ; |
ffxx68 | 0:07819bc70660 | 578 | uint32_t nbByte; |
ffxx68 | 0:07819bc70660 | 579 | uint32_t nbSync = N_SYNC_BITS; |
ffxx68 | 0:07819bc70660 | 580 | uint32_t addr; |
ffxx68 | 0:07819bc70660 | 581 | int error ; |
ffxx68 | 0:07819bc70660 | 582 | char inVal; |
ffxx68 | 0:07819bc70660 | 583 | |
ffxx68 | 0:07819bc70660 | 584 | |
ffxx68 | 0:07819bc70660 | 585 | // BIN file stored statically, until I integrate an SD-Card... |
ffxx68 | 0:07819bc70660 | 586 | nbByte = FileSize; |
ffxx68 | 0:07819bc70660 | 587 | ptrFile->nbSync = nbSync; |
ffxx68 | 0:07819bc70660 | 588 | |
ffxx68 | 0:07819bc70660 | 589 | if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG ptrFile->ident %u\n\r",ptrFile->ident); |
ffxx68 | 0:07819bc70660 | 590 | if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG nbSync %u\n\r",nbSync); |
ffxx68 | 0:07819bc70660 | 591 | if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG nbByte %u\n\r",nbByte); |
ffxx68 | 0:07819bc70660 | 592 | |
ffxx68 | 0:07819bc70660 | 593 | switch (ptrFile->ident) { |
ffxx68 | 0:07819bc70660 | 594 | /* . . .*/ |
ffxx68 | 0:07819bc70660 | 595 | case IDENT_NEW_BIN : |
ffxx68 | 0:07819bc70660 | 596 | pcgrpId = GRP_NEW ; /*or GRP_EXT */ |
ffxx68 | 0:07819bc70660 | 597 | type = TYPE_BIN ; |
ffxx68 | 0:07819bc70660 | 598 | break ; |
ffxx68 | 0:07819bc70660 | 599 | /* . . .*/ |
ffxx68 | 0:07819bc70660 | 600 | case IDENT_NEW_BAS : |
ffxx68 | 0:07819bc70660 | 601 | pcgrpId = GRP_NEW ; |
ffxx68 | 0:07819bc70660 | 602 | type = TYPE_IMG ; |
ffxx68 | 0:07819bc70660 | 603 | break ; |
ffxx68 | 0:07819bc70660 | 604 | default : |
ffxx68 | 0:07819bc70660 | 605 | printf ("%s: Unknown Ident\n", argP) ; |
ffxx68 | 0:07819bc70660 | 606 | return (ERR_ARG); |
ffxx68 | 0:07819bc70660 | 607 | } |
ffxx68 | 0:07819bc70660 | 608 | |
ffxx68 | 0:07819bc70660 | 609 | /* if (pcgrpId == GRP_E || pcgrpId == GRP_G || pcgrpId == GRP_16) { |
ffxx68 | 0:07819bc70660 | 610 | . . . |
ffxx68 | 0:07819bc70660 | 611 | } |
ffxx68 | 0:07819bc70660 | 612 | else { // PC-1211 to PC-1500, QTape |
ffxx68 | 0:07819bc70660 | 613 | */ |
ffxx68 | 0:07819bc70660 | 614 | if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG WriteSyncToWav\n\r"); |
ffxx68 | 0:07819bc70660 | 615 | error = WriteSyncToWav (nbSync, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 616 | /* |
ffxx68 | 0:07819bc70660 | 617 | . . . |
ffxx68 | 0:07819bc70660 | 618 | */ |
ffxx68 | 0:07819bc70660 | 619 | if (error != ERR_OK) return ( error ) ; |
ffxx68 | 0:07819bc70660 | 620 | |
ffxx68 | 0:07819bc70660 | 621 | switch (pcId) { |
ffxx68 | 0:07819bc70660 | 622 | /* |
ffxx68 | 0:07819bc70660 | 623 | . . . |
ffxx68 | 0:07819bc70660 | 624 | */ |
ffxx68 | 0:07819bc70660 | 625 | case 1403: |
ffxx68 | 0:07819bc70660 | 626 | /* if (type == TYPE_BIN && Acnt==0 && SHCc==0 && addr==0) */ addr = TYPE_BIN_ADDR; |
ffxx68 | 0:07819bc70660 | 627 | /* |
ffxx68 | 0:07819bc70660 | 628 | . . . |
ffxx68 | 0:07819bc70660 | 629 | */ |
ffxx68 | 0:07819bc70660 | 630 | break; |
ffxx68 | 0:07819bc70660 | 631 | default : |
ffxx68 | 0:07819bc70660 | 632 | printf ("%s: Pocket computer %d is not implemented\n", argP, pcId) ; |
ffxx68 | 0:07819bc70660 | 633 | // MoreInfo (ERR_ARG); |
ffxx68 | 0:07819bc70660 | 634 | error = ERR_ARG ; |
ffxx68 | 0:07819bc70660 | 635 | // break ; |
ffxx68 | 0:07819bc70660 | 636 | } |
ffxx68 | 0:07819bc70660 | 637 | if (error != ERR_OK) return ( error ) ; |
ffxx68 | 0:07819bc70660 | 638 | |
ffxx68 | 0:07819bc70660 | 639 | /* ... |
ffxx68 | 0:07819bc70660 | 640 | else { // PC-121x ... PC-1475 |
ffxx68 | 0:07819bc70660 | 641 | */ |
ffxx68 | 0:07819bc70660 | 642 | if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG set Header Mode\n\r"); |
ffxx68 | 0:07819bc70660 | 643 | switch (ptrFile->ident) { /* Header Mode */ |
ffxx68 | 0:07819bc70660 | 644 | case IDENT_PC1211 : |
ffxx68 | 0:07819bc70660 | 645 | ptrFile->mode = ptrFile->mode_h = MODE_B20 ; |
ffxx68 | 0:07819bc70660 | 646 | break ; |
ffxx68 | 0:07819bc70660 | 647 | |
ffxx68 | 0:07819bc70660 | 648 | case IDENT_PC121_DAT : |
ffxx68 | 0:07819bc70660 | 649 | case IDENT_OLD_BAS : |
ffxx68 | 0:07819bc70660 | 650 | case IDENT_OLD_DAT : |
ffxx68 | 0:07819bc70660 | 651 | case IDENT_OLD_BIN : |
ffxx68 | 0:07819bc70660 | 652 | case IDENT_OLD_MEM : |
ffxx68 | 0:07819bc70660 | 653 | ptrFile->mode = ptrFile->mode_h = MODE_B19 ; |
ffxx68 | 0:07819bc70660 | 654 | break ; |
ffxx68 | 0:07819bc70660 | 655 | |
ffxx68 | 0:07819bc70660 | 656 | case IDENT_NEW_TEL : |
ffxx68 | 0:07819bc70660 | 657 | case IDENT_NEW_SCD : |
ffxx68 | 0:07819bc70660 | 658 | case IDENT_NEW_NOT : |
ffxx68 | 0:07819bc70660 | 659 | case IDENT_NEW_CRD : |
ffxx68 | 0:07819bc70660 | 660 | |
ffxx68 | 0:07819bc70660 | 661 | case IDENT_NEW_CSL : |
ffxx68 | 0:07819bc70660 | 662 | |
ffxx68 | 0:07819bc70660 | 663 | case IDENT_NEW_BAS : |
ffxx68 | 0:07819bc70660 | 664 | case IDENT_EXT_BAS : |
ffxx68 | 0:07819bc70660 | 665 | case IDENT_NEW_DAT : |
ffxx68 | 0:07819bc70660 | 666 | case IDENT_NEW_BIN : |
ffxx68 | 0:07819bc70660 | 667 | ptrFile->mode = ptrFile->mode_h = MODE_B16 ; |
ffxx68 | 0:07819bc70660 | 668 | break ; |
ffxx68 | 0:07819bc70660 | 669 | |
ffxx68 | 0:07819bc70660 | 670 | default : |
ffxx68 | 0:07819bc70660 | 671 | printf ("%s: Unknown Ident\n", argP) ; |
ffxx68 | 0:07819bc70660 | 672 | ptrFile->mode = ptrFile->mode_h = MODE_B21 ; |
ffxx68 | 0:07819bc70660 | 673 | return (ERR_ARG); |
ffxx68 | 0:07819bc70660 | 674 | } |
ffxx68 | 0:07819bc70660 | 675 | if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG Header ptrFile->mode_h %u\n\r",ptrFile->mode_h); |
ffxx68 | 0:07819bc70660 | 676 | |
ffxx68 | 0:07819bc70660 | 677 | /* Write the TAPE code */ |
ffxx68 | 0:07819bc70660 | 678 | if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG Write the TAPE code\n\r"); |
ffxx68 | 0:07819bc70660 | 679 | error = WriteByteToWav ( (ulong) ptrFile->ident, ORDER_STD, ptrFile->mode_h, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 680 | if (error != ERR_OK) return ( error ) ; |
ffxx68 | 0:07819bc70660 | 681 | |
ffxx68 | 0:07819bc70660 | 682 | /* Write the Name */ |
ffxx68 | 0:07819bc70660 | 683 | if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG Write the Name\n\r"); |
ffxx68 | 0:07819bc70660 | 684 | error = WriteSaveNameToWav ( FileName, ptrFile->mode_h, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 685 | if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG error (ERR_OK) %d (%d)\n\r", error, ERR_OK); |
ffxx68 | 0:07819bc70660 | 686 | if (error != ERR_OK) return ( error ) ; |
ffxx68 | 0:07819bc70660 | 687 | |
ffxx68 | 0:07819bc70660 | 688 | if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG set Body Data Mode\n\r"); |
ffxx68 | 0:07819bc70660 | 689 | switch (ptrFile->ident) { /* Body Data Mode */ |
ffxx68 | 0:07819bc70660 | 690 | case IDENT_PC1211 : |
ffxx68 | 0:07819bc70660 | 691 | ptrFile->mode = MODE_B20 ; |
ffxx68 | 0:07819bc70660 | 692 | break ; |
ffxx68 | 0:07819bc70660 | 693 | |
ffxx68 | 0:07819bc70660 | 694 | case IDENT_PC121_DAT : |
ffxx68 | 0:07819bc70660 | 695 | case IDENT_OLD_BAS : |
ffxx68 | 0:07819bc70660 | 696 | case IDENT_OLD_BIN : |
ffxx68 | 0:07819bc70660 | 697 | case IDENT_OLD_MEM : |
ffxx68 | 0:07819bc70660 | 698 | ptrFile->mode = MODE_B19 ; |
ffxx68 | 0:07819bc70660 | 699 | break ; |
ffxx68 | 0:07819bc70660 | 700 | |
ffxx68 | 0:07819bc70660 | 701 | case IDENT_OLD_DAT : |
ffxx68 | 0:07819bc70660 | 702 | case IDENT_NEW_DAT : |
ffxx68 | 0:07819bc70660 | 703 | ptrFile->mode = MODE_B15 ; |
ffxx68 | 0:07819bc70660 | 704 | break ; |
ffxx68 | 0:07819bc70660 | 705 | |
ffxx68 | 0:07819bc70660 | 706 | case IDENT_EXT_BAS : |
ffxx68 | 0:07819bc70660 | 707 | |
ffxx68 | 0:07819bc70660 | 708 | case IDENT_NEW_BAS : |
ffxx68 | 0:07819bc70660 | 709 | case IDENT_NEW_CSL : |
ffxx68 | 0:07819bc70660 | 710 | |
ffxx68 | 0:07819bc70660 | 711 | case IDENT_NEW_TEL : |
ffxx68 | 0:07819bc70660 | 712 | case IDENT_NEW_SCD : |
ffxx68 | 0:07819bc70660 | 713 | case IDENT_NEW_NOT : |
ffxx68 | 0:07819bc70660 | 714 | case IDENT_NEW_CRD : |
ffxx68 | 0:07819bc70660 | 715 | case IDENT_NEW_BIN : |
ffxx68 | 0:07819bc70660 | 716 | // TODO (mr#2#): Check whitch MODE_B13 or _B14 |
ffxx68 | 0:07819bc70660 | 717 | if (cnvstr_upr && pcId < 1440) ptrFile->mode = MODE_B13 ; /*older part of new series*/ |
ffxx68 | 0:07819bc70660 | 718 | else ptrFile->mode = MODE_B14 ; /*new series and extended series*/ |
ffxx68 | 0:07819bc70660 | 719 | break ; |
ffxx68 | 0:07819bc70660 | 720 | |
ffxx68 | 0:07819bc70660 | 721 | default : |
ffxx68 | 0:07819bc70660 | 722 | printf ("%s: Unknown Ident\n", argP) ; |
ffxx68 | 0:07819bc70660 | 723 | return ( ERR_ARG ); |
ffxx68 | 0:07819bc70660 | 724 | } |
ffxx68 | 0:07819bc70660 | 725 | if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG Body ptrFile->mode %u\n\r", ptrFile->mode); |
ffxx68 | 0:07819bc70660 | 726 | |
ffxx68 | 0:07819bc70660 | 727 | ptrFile->total = 0 ; /* count bytes of body only */ |
ffxx68 | 0:07819bc70660 | 728 | |
ffxx68 | 0:07819bc70660 | 729 | switch (ptrFile->ident) { /* header was written, write all data now */ |
ffxx68 | 0:07819bc70660 | 730 | /* ... |
ffxx68 | 0:07819bc70660 | 731 | case |
ffxx68 | 0:07819bc70660 | 732 | ... */ |
ffxx68 | 0:07819bc70660 | 733 | case IDENT_NEW_BAS : |
ffxx68 | 0:07819bc70660 | 734 | case IDENT_NEW_CSL : |
ffxx68 | 0:07819bc70660 | 735 | case IDENT_EXT_BAS : |
ffxx68 | 0:07819bc70660 | 736 | if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG Write the datas\n\r"); |
ffxx68 | 0:07819bc70660 | 737 | /* Write the datas */ |
ffxx68 | 0:07819bc70660 | 738 | // info.mode = MODE_B13 ; /*PC-1403 and newer should be MODE_14 */ |
ffxx68 | 0:07819bc70660 | 739 | /* the older simple algorithm seems to work as well, but this is now, what the PC does originally */ |
ffxx68 | 0:07819bc70660 | 740 | for ( ii = 0 ; ii < nbByte - 1 ; ++ii ) { |
ffxx68 | 0:07819bc70660 | 741 | if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG LOOP ii %u\n\r", ii); |
ffxx68 | 0:07819bc70660 | 742 | |
ffxx68 | 0:07819bc70660 | 743 | inVal = FileStream[ii] ; // fgetc (srcFd) ; |
ffxx68 | 0:07819bc70660 | 744 | if ( inVal == EOF ) break ; |
ffxx68 | 0:07819bc70660 | 745 | |
ffxx68 | 0:07819bc70660 | 746 | if ( inVal == BAS_NEW_EOF ) { |
ffxx68 | 0:07819bc70660 | 747 | if (ptrFile->count + 1 == BLK_NEW && ptrFile->sum == 0xE1) { /* Constellation will generate 2-times BAS_NEW_EOF */ |
ffxx68 | 0:07819bc70660 | 748 | printf ("\nERROR %i at %lu. byte, usually the low byte of a BASIC line number\n", ERR_SUM, ptrFile->total) ; |
ffxx68 | 0:07819bc70660 | 749 | printf ("This binary constellation activates the CLOAD bug of this series. The line\n") ; |
ffxx68 | 0:07819bc70660 | 750 | printf ("number must be changed or minor changes done in the BASIC text before.\n") ; |
ffxx68 | 0:07819bc70660 | 751 | /* Seldom Bug in CLOAD, for PC-1402/(01) at known ROM address: 40666 */ |
ffxx68 | 0:07819bc70660 | 752 | if ((ptrFile->debug & 0x800) == 0 ) { |
ffxx68 | 0:07819bc70660 | 753 | error = ERR_SUM ; |
ffxx68 | 0:07819bc70660 | 754 | break ; |
ffxx68 | 0:07819bc70660 | 755 | } |
ffxx68 | 0:07819bc70660 | 756 | } |
ffxx68 | 0:07819bc70660 | 757 | } |
ffxx68 | 0:07819bc70660 | 758 | error = WriteByteSumToWav ( (uint) inVal, ORDER_STD, ptrFile->mode, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 759 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 760 | } |
ffxx68 | 0:07819bc70660 | 761 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 762 | if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG ii %u\n\r", ii); |
ffxx68 | 0:07819bc70660 | 763 | |
ffxx68 | 0:07819bc70660 | 764 | inVal = FileStream[ii] ; // fgetc (srcFd) ; /* Read the last byte before EOF mark */ |
ffxx68 | 0:07819bc70660 | 765 | if (inVal == EOF) break ; |
ffxx68 | 0:07819bc70660 | 766 | |
ffxx68 | 0:07819bc70660 | 767 | if (inVal == BAS_NEW_EOF) { |
ffxx68 | 0:07819bc70660 | 768 | /* EOF mark should not be included for this file type normally*/ |
ffxx68 | 0:07819bc70660 | 769 | if (Qcnt == 0) printf ("End of File mark %i should not be included in the image\n", inVal) ; |
ffxx68 | 0:07819bc70660 | 770 | /* if end of block, then an additional checksum would be written, but this does work anyhow */ |
ffxx68 | 0:07819bc70660 | 771 | } |
ffxx68 | 0:07819bc70660 | 772 | else { |
ffxx68 | 0:07819bc70660 | 773 | if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG last byte: %02X\n\r", (uchar) inVal); |
ffxx68 | 0:07819bc70660 | 774 | error = WriteByteToWav ( (uint) inVal, ORDER_STD, ptrFile->mode, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 775 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 776 | CheckSumB1 ((uint) inVal, ptrFile) ; /* never write the checksum before BAS_NEW_EOF */ |
ffxx68 | 0:07819bc70660 | 777 | |
ffxx68 | 0:07819bc70660 | 778 | ++ptrFile->total ; |
ffxx68 | 0:07819bc70660 | 779 | ++ptrFile->count ; /* for debug purposes only, WriteFooter will reset it */ |
ffxx68 | 0:07819bc70660 | 780 | } |
ffxx68 | 0:07819bc70660 | 781 | |
ffxx68 | 0:07819bc70660 | 782 | /* Write the END code */ |
ffxx68 | 0:07819bc70660 | 783 | if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG WriteFooterToNewWav prima\n\r"); |
ffxx68 | 0:07819bc70660 | 784 | error = WriteFooterToNewWav (ptrFile) ; |
ffxx68 | 0:07819bc70660 | 785 | |
ffxx68 | 0:07819bc70660 | 786 | break ; // IDENT_NEW_BAS, IDENT_EXT_BAS |
ffxx68 | 0:07819bc70660 | 787 | |
ffxx68 | 0:07819bc70660 | 788 | case IDENT_NEW_BIN : |
ffxx68 | 0:07819bc70660 | 789 | /* Write the address and length */ |
ffxx68 | 0:07819bc70660 | 790 | error = WriteHeadToBinWav (addr, nbByte, ptrFile->mode_h, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 791 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 792 | /* no break */ |
ffxx68 | 0:07819bc70660 | 793 | |
ffxx68 | 0:07819bc70660 | 794 | case IDENT_NEW_TEL : |
ffxx68 | 0:07819bc70660 | 795 | case IDENT_NEW_SCD : |
ffxx68 | 0:07819bc70660 | 796 | case IDENT_NEW_NOT : |
ffxx68 | 0:07819bc70660 | 797 | case IDENT_NEW_CRD : |
ffxx68 | 0:07819bc70660 | 798 | |
ffxx68 | 0:07819bc70660 | 799 | /* Write the datas */ |
ffxx68 | 0:07819bc70660 | 800 | for ( ii = 0 ; ii < nbByte - 1 ; ++ii ) { |
ffxx68 | 0:07819bc70660 | 801 | inVal = FileStream[ii] ; // fgetc (srcFd) ; |
ffxx68 | 0:07819bc70660 | 802 | if (inVal == EOF) break ; // Should not happen ... |
ffxx68 | 0:07819bc70660 | 803 | |
ffxx68 | 0:07819bc70660 | 804 | error = WriteByteSumToWav ( (uint) inVal, ORDER_STD, ptrFile->mode, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 805 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 806 | } |
ffxx68 | 0:07819bc70660 | 807 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 808 | |
ffxx68 | 0:07819bc70660 | 809 | inVal = FileStream[ii] ; // fgetc (srcFd) ; /* Read the last byte before EOF mark */ |
ffxx68 | 0:07819bc70660 | 810 | if (inVal == EOF) break ; |
ffxx68 | 0:07819bc70660 | 811 | |
ffxx68 | 0:07819bc70660 | 812 | if ( (ptrFile->debug & 0x0040) > 0 ) printf(" %02X", (uchar) inVal); |
ffxx68 | 0:07819bc70660 | 813 | error = WriteByteToWav ( (uint) inVal, ORDER_STD, ptrFile->mode, ptrFile) ; |
ffxx68 | 0:07819bc70660 | 814 | if (error != ERR_OK) break ; |
ffxx68 | 0:07819bc70660 | 815 | CheckSumB1 ( (uint) inVal, ptrFile ) ; /* never write the checksum before BAS_NEW_EOF */ |
ffxx68 | 0:07819bc70660 | 816 | ++ptrFile->total ; |
ffxx68 | 0:07819bc70660 | 817 | ++ptrFile->count ; /* for debug purposes only, WriteFooter will reset it */ |
ffxx68 | 0:07819bc70660 | 818 | |
ffxx68 | 0:07819bc70660 | 819 | /* Write the END code */ |
ffxx68 | 0:07819bc70660 | 820 | if ( ptrFile->ident == IDENT_NEW_BIN) error = WriteFooterToNewWav ( ptrFile ) ; |
ffxx68 | 0:07819bc70660 | 821 | else WriteFooterToMemoWav ( ptrFile ) ; |
ffxx68 | 0:07819bc70660 | 822 | |
ffxx68 | 0:07819bc70660 | 823 | break ; // IDENT_NEW_BIN and IDENT_NEW_Memos |
ffxx68 | 0:07819bc70660 | 824 | default: |
ffxx68 | 0:07819bc70660 | 825 | printf ("%s: Unknown Ident\n", argP) ; |
ffxx68 | 0:07819bc70660 | 826 | error = ERR_ARG; |
ffxx68 | 0:07819bc70660 | 827 | break; |
ffxx68 | 0:07819bc70660 | 828 | } |
ffxx68 | 0:07819bc70660 | 829 | |
ffxx68 | 0:07819bc70660 | 830 | if ( (ptrFile->debug & 0x0040) > 0 ) printf("DEBUG FileSend error %d\n\r", error); |
ffxx68 | 0:07819bc70660 | 831 | return (error); |
ffxx68 | 0:07819bc70660 | 832 | |
ffxx68 | 0:07819bc70660 | 833 | } |