Renamed

Dependencies:   mbed

Revision:
5:062962db7a48
Parent:
2:dff96be9617e
--- a/send_pc1403.cpp	Wed Feb 23 12:24:16 2022 +0000
+++ b/send_pc1403.cpp	Tue Mar 29 10:06:20 2022 +0000
@@ -1,5 +1,4 @@
 #include "send_pc1403.h"
-#include "bit_send.h"
 
 ///////////////////////////////////////////////////////
 // variables from PocketTools code
@@ -24,11 +23,12 @@
 ulong  err_cnt = 0 ;    /* counts minor errors */
 ulong  wrn_cnt = 0 ;    /* counts warnings */
 
+FileInfo  fileInfo ;    /* File information */
+
 ////////////////////////////////////////////////////////////////////////////////
 // WriteBitToWav replaced from PocketTools version (writing to a WAV file)
 // Here we send directly signals to OUT lines
-int WriteBitToWav (int   value,
-              FileInfo*  ptrFile)
+int WriteBitToWav (int   value)
 {
     // Calling the buffered bit-sending routine
     switch ( value ) {
@@ -51,33 +51,32 @@
 // 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   stopBits)
 {
       uint  tmp ;
       uint  ii ;
        int  error ;
 
-    // if (TAPc > 0) return (WriteQuaterToTap (value, ptrFile)); // no  
+    // if (TAPc > 0) return (WriteQuaterToTap (value )); // no  
     
     do {
         
-        error = WriteBitToWav (0, ptrFile) ;
+        error = WriteBitToWav (0 ) ;
         if (error != ERR_OK) break ;
 
         for ( ii = 0 ; ii < 4 ; ++ii ) {
             tmp = 1 << ii ;
             if ( (value & tmp) == 0 )
-                error = WriteBitToWav (0, ptrFile) ;
+                error = WriteBitToWav (0 ) ;
             else
-                error = WriteBitToWav (1, ptrFile) ;
+                error = WriteBitToWav (1 ) ;
 
             if (error != ERR_OK) break ;
         }
         if (error != ERR_OK) break ;
 
         for ( ii = 0 ; ii < stopBits ; ++ii ) {
-            error = WriteBitToWav (1, ptrFile) ;
+            error = WriteBitToWav (1 ) ;
             if (error != ERR_OK) break ;
         }
         if (error != ERR_OK) break ;
@@ -88,30 +87,29 @@
 
 int WriteByteToWav (ulong  value,
                     uchar  order,
-                    uchar  mode,
-                FileInfo*  ptrFile)
+                    uchar  mode)
 {
       uint  lsq ;
       uint  msq ;
       int  error ;
 
-    // if (TAPc > 0) return (WriteByteToTap (value, order, ptrFile)) ; // no  
+    // if (TAPc > 0) return (WriteByteToTap (value, order )) ; // no  
 
-    // if (order == ORDER_E) return (WriteByteToEWav (value, ptrFile)) ; // no  1403
+    // if (order == ORDER_E) return (WriteByteToEWav (value )) ; // no  1403
 
     do {
         lsq = value & 0x0F ;
         msq = (value >> 4) & 0x0F ;
         if (order == ORDER_INV) {
-            error = WriteQuaterToWav (lsq, Mode[mode].stopb1, ptrFile) ;
+            error = WriteQuaterToWav (lsq, Mode[mode].stopb1 ) ;
             if (error != ERR_OK) break ;
-            error = WriteQuaterToWav (msq, Mode[mode].stopb2, ptrFile) ;
+            error = WriteQuaterToWav (msq, Mode[mode].stopb2 ) ;
             if (error != ERR_OK) break ;
         }
         else {
-            error = WriteQuaterToWav (msq, Mode[mode].stopb1, ptrFile) ;
+            error = WriteQuaterToWav (msq, Mode[mode].stopb1 ) ;
             if (error != ERR_OK) break ;
-            error = WriteQuaterToWav (lsq, Mode[mode].stopb2, ptrFile) ;
+            error = WriteQuaterToWav (lsq, Mode[mode].stopb2 ) ;
             if (error != ERR_OK) break ;
         }
 
@@ -119,26 +117,25 @@
     return (error);
 }
 
-int CheckSumB1 (  ulong  Byte,
-              FileInfo*  ptrFile)
+int CheckSumB1 (  ulong  Byte )
 {
     ushort sum ;
 
     /* Update the checksum */
-        sum = ptrFile->sum + ((Byte & 0xF0) >> 4) ;
+        sum = fileInfo.sum + ((Byte & 0xF0) >> 4) ;
         if (sum > 0xFF) {
             ++sum ;
             sum &= 0xFF ;
             }
-        ptrFile->sum = (sum + (Byte & 0x0F)) & 0xFF ;
+        fileInfo.sum = (sum + (Byte & 0x0F)) & 0xFF ;
 
     return (0);
 }
 
 
-int CheckSumE (  ulong  Byte,
-//               ulong*  ptrSum )
-               FileInfo*  ptrFile)
+int CheckSumE (  ulong  Byte 
+//               ulong*  ptrSum 
+      )
 {
     uint tmp, ii ;
 
@@ -147,14 +144,13 @@
     for ( ii = 0 ; ii < 8 ; ++ii, tmp >>= 1 )
         if ( (Byte & tmp) != 0 )  
             // ++ *ptrSum ;
-             ++ ptrFile->sum ;
+             ++ fileInfo.sum ;
 
     return (0);
 }
 
 
-int WriteSyncToWav (ulong  nbSync,  // 
-                FileInfo*  ptrFile)
+int WriteSyncToWav (ulong  nbSync )
 {
     ulong  ii ;
     int    error = ERR_OK ;
@@ -164,7 +160,7 @@
     do {
         /* Write the Synchro patern */
         for ( ii = 0 ; ii < nbSync ; ++ii ) {
-            error = WriteBitToWav (1, ptrFile) ;
+            error = WriteBitToWav (1 ) ;
             if (error != ERR_OK) break ;
         }
         if (error != ERR_OK) break ;
@@ -174,62 +170,58 @@
 }
 
 int WriteUsedatLenToQTWav ( uchar  order, /* Quick-Tape incomplete blocks with fill data */
-                            uchar  mode,
-                        FileInfo*  ptrFile)
+                            uchar  mode )
 {   long tmpL ;
     int  error ;
 
-    tmpL = ptrFile->nbByte - ptrFile->total_diff - ptrFile->total ; //not for IDENT_QT_DAT: variable block in RAM based
+    tmpL = fileInfo.nbByte - fileInfo.total_diff - fileInfo.total ; //not for IDENT_QT_DAT: variable block in RAM based
 
     if (tmpL > 0) {
             if (tmpL > BLK_OLD) tmpL = BLK_OLD ;
             --tmpL ;
-            if (tmpL < BLK_OLD -1) ptrFile->usedat_len = tmpL + 1 ;
-            else ptrFile->usedat_len = 0 ; /* L:0x4F ignored, no effect */
+            if (tmpL < BLK_OLD -1) fileInfo.usedat_len = tmpL + 1 ;
+            else fileInfo.usedat_len = 0 ; /* L:0x4F ignored, no effect */
 
-            error = WriteByteToWav (tmpL, order, mode, ptrFile) ;
+            error = WriteByteToWav (tmpL, order, mode ) ;
             if (error != ERR_OK) return (error) ;
-            if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG (L:%02X)", (uint) tmpL);
+            if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG (L:%02X)", (uint) tmpL);
 
-            ptrFile->sum = tmpL ;
+            fileInfo.sum = tmpL ;
     }
     else if (tmpL == 0 ) error = ERR_OK ;
     else {
             printf(" WUsedatLQT: End of file was expected");
             error = ERR_FMT ;
     }
-    ptrFile->count = 0 ;
+    fileInfo.count = 0 ;
 
     return (error);
 }
 
 int WriteByteSumToWav (ulong  value,
                        uchar  order,
-                       uchar  mode,
-                       FileInfo*  ptrFile)
+                       uchar  mode)
 {
     int   error ;
     bool  writ_full_block = false ;
     
     do {
 
-        if ( (ptrFile->debug & 0x0040) > 0) {
+        if ( (fileInfo.debug & 0x0040) > 0)  
             debug_printf(" %02X", (uchar) value);
-            if ( ptrFile->total %0x100 == 0xFF ) printf("\n");
-        }
-        error = WriteByteToWav (value, order, mode, ptrFile) ;
+        error = WriteByteToWav (value, order, mode ) ;
         if (error != ERR_OK) break ;
 
-        if (mode == MODE_B22 || mode == MODE_B11) ptrFile->sum += value ;
-        else if (mode == MODE_B9 || mode == MODE_B10) CheckSumE (value, ptrFile) ; //ptrFile
-        else CheckSumB1 (value, ptrFile) ;
+        if (mode == MODE_B22 || mode == MODE_B11) fileInfo.sum += value ;
+        else if (mode == MODE_B9 || mode == MODE_B10) CheckSumE (value ) ; //ptrFile
+        else CheckSumB1 (value ) ;
 
-        ++ptrFile->count ;
-        if (!writ_full_block) ++ptrFile->total ;
+        ++fileInfo.count ;
+        if (!writ_full_block) ++fileInfo.total ;
 
-        if ( ptrFile->usedat_len > 0) { /* QTape incomplete block */
-            if (--ptrFile->usedat_len == 0) {
-                if ( ( (ptrFile->debug & 0x0040) > 0 ) && (Qcnt == 0) ) debug_printf("DEBUG Fill data:");
+        if ( fileInfo.usedat_len > 0) { /* QTape incomplete block */
+            if (--fileInfo.usedat_len == 0) {
+                if ( ( (fileInfo.debug & 0x0040) > 0 ) && (Qcnt == 0) ) debug_printf("DEBUG Fill data:");
                 value = 0x00 ;
                 writ_full_block = true ;
             }
@@ -237,40 +229,40 @@
 
         switch (mode) {
         case MODE_B22 :
-            if ( ptrFile->count >= BLK_OLD ) {
+            if ( fileInfo.count >= BLK_OLD ) {
 
-                if ( (ptrFile->debug & 0x0040) > 0 )
-                    debug_printf(" (%04X)", (uint) ptrFile->sum);
+                if ( (fileInfo.debug & 0x0040) > 0 )
+                    debug_printf(" (%04X)\n\r", (uint) fileInfo.sum);
 
                 /* Write the checksum */
-                error = WriteByteToWav (ptrFile->sum >> 8 & 0xFF, order, mode, ptrFile) ;
+                error = WriteByteToWav (fileInfo.sum >> 8 & 0xFF, order, mode ) ;
                 if (error != ERR_OK) break ;
-                error = WriteByteToWav (ptrFile->sum & 0xFF, order, mode, ptrFile) ;
+                error = WriteByteToWav (fileInfo.sum & 0xFF, order, mode ) ;
                 if (error != ERR_OK) break ;
 
-                ptrFile->count = 0 ;
-                ptrFile->sum   = 0 ;
+                fileInfo.count = 0 ;
+                fileInfo.sum   = 0 ;
             }
             break ;
 
         case MODE_B21 :
         case MODE_B20 :
         case MODE_B19 :
-            if ( (ptrFile->count % BLK_OLD_SUM) == 0) {
+            if ( (fileInfo.count % BLK_OLD_SUM) == 0) {
 
-                if ( (ptrFile->debug & 0x0040) > 0 )
-                    debug_printf(" (%02X)", (uchar) ptrFile->sum);
+                if ( (fileInfo.debug & 0x0040) > 0 )
+                    debug_printf(" (%02X)\n\r", (uchar) fileInfo.sum);
 
                 /* Write the checksum */
-                error = WriteByteToWav (ptrFile->sum, order, mode, ptrFile) ;
+                error = WriteByteToWav (fileInfo.sum, order, mode ) ;
                 if (error != ERR_OK) break ;
 
-                if ( ptrFile->count >= BLK_OLD ) {
-                    ptrFile->count = 0 ;
-                    ptrFile->sum   = 0 ;
-                    // if (pcgrpId==IDENT_PC1211) error = WriteSyncToWav (1803, ptrFile) ; //DATA not
-                    if (ptrFile->ident == IDENT_PC1211) /* default 1803 bits, data not */
-                        error = WriteSyncToWav (ptrFile->nbSync, ptrFile) ;
+                if ( fileInfo.count >= BLK_OLD ) {
+                    fileInfo.count = 0 ;
+                    fileInfo.sum   = 0 ;
+                    // if (pcgrpId==IDENT_PC1211) error = WriteSyncToWav (1803 ) ; //DATA not
+                    if (fileInfo.ident == IDENT_PC1211) /* default 1803 bits, data not */
+                        error = WriteSyncToWav (fileInfo.nbSync ) ;
                 }
             }
             break ;
@@ -278,93 +270,93 @@
         case MODE_B17 :
         case MODE_B16 :
         case MODE_B15 :
-            if ( ptrFile->count >= BLK_OLD_SUM) {
+            if ( fileInfo.count >= BLK_OLD_SUM) {
 
-                if ( (ptrFile->debug & 0x0040) > 0 )
-                    debug_printf(" (%02X)", (uchar) ptrFile->sum);
+                if ( (fileInfo.debug & 0x0040) > 0 )
+                    debug_printf(" (%02X)\n\r", (uchar) fileInfo.sum);
 
                 /* Write the checksum */
-                error = WriteByteToWav (ptrFile->sum, order, mode, ptrFile) ;
+                error = WriteByteToWav (fileInfo.sum, order, mode) ;
                 if (error != ERR_OK) break ;
 
-                ptrFile->count = 0 ;
-                ptrFile->sum   = 0 ;
+                fileInfo.count = 0 ;
+                fileInfo.sum   = 0 ;
             }
             break ;
 
         case MODE_B14 :
         case MODE_B13 :
-            if ( ptrFile->count >= BLK_NEW) {
+            if ( fileInfo.count >= BLK_NEW ) {
 
-                if ( (ptrFile->debug & 0x0040) > 0 )
-                    debug_printf(" (%02X)", (uchar) ptrFile->sum);
+                if ( (fileInfo.debug & 0x0040) > 0 )
+                    debug_printf(" *(%02X)", (uchar) fileInfo.sum);
 
                 /* Write the checksum */
-                error = WriteByteToWav (ptrFile->sum, order, mode, ptrFile) ;
+                error = WriteByteToWav (fileInfo.sum, order, mode ) ;
                 if (error != ERR_OK) break ;
 
-                ptrFile->count = 0 ;
-                ptrFile->sum   = 0 ;
+                fileInfo.count = 0 ;
+                fileInfo.sum   = 0 ;
             }
             break ;
 
         case MODE_B9 : /* PC-E/G/1600 */
-            if ( ptrFile->count >= ptrFile->block_len ) {
+            if ( fileInfo.count >= fileInfo.block_len ) {
 
-                if ( (ptrFile->debug & 0x0040) > 0 )
-                    debug_printf(" (%04X)", (uint) ptrFile->sum & 0xFFFF);
+                if ( (fileInfo.debug & 0x0040) > 0 )
+                    debug_printf(" (%04X)\n\r", (uint) fileInfo.sum & 0xFFFF);
 
                 /* Write the checksum */
-                error = WriteByteToWav (ptrFile->sum >> 8 & 0xFF, order, mode, ptrFile) ;
+                error = WriteByteToWav (fileInfo.sum >> 8 & 0xFF, order, mode ) ;
                 if (error != ERR_OK) break ;
-                error = WriteByteToWav (ptrFile->sum & 0xFF, order, mode, ptrFile) ;
+                error = WriteByteToWav (fileInfo.sum & 0xFF, order, mode ) ;
                 if (error != ERR_OK) break ;
 
-                ptrFile->count = 0 ;
-                ptrFile->sum   = 0 ;
+                fileInfo.count = 0 ;
+                fileInfo.sum   = 0 ;
             }
             break ;
 
         case MODE_B10 : /* SuperTape */
-            if ( ptrFile->count >= ptrFile->block_len ) {
+            if ( fileInfo.count >= fileInfo.block_len ) {
 
-                if ( (ptrFile->debug & 0x0040) > 0 )
-                    debug_printf(" (%04X)", (uint) ptrFile->sum & 0xFFFF);
+                if ( (fileInfo.debug & 0x0040) > 0 )
+                    debug_printf(" (%04X)", (uint) fileInfo.sum & 0xFFFF);
 
                 /* Write the checksum */
-                error = WriteByteToWav (ptrFile->sum & 0xFF, order, mode, ptrFile) ;
+                error = WriteByteToWav (fileInfo.sum & 0xFF, order, mode ) ;
                 if (error != ERR_OK) break ;
-                error = WriteByteToWav (ptrFile->sum >> 8 & 0xFF, order, mode, ptrFile) ;
+                error = WriteByteToWav (fileInfo.sum >> 8 & 0xFF, order, mode ) ;
                 if (error != ERR_OK) break ;
 
-                if ( (ptrFile->debug & 0x0040) > 0) debug_printf(" %02X", (uchar) SUPT_END);
-                error = WriteByteToWav (SUPT_END, order, mode, ptrFile) ;
+                if ( (fileInfo.debug & 0x0040) > 0) debug_printf(" %02X", (uchar) SUPT_END);
+                error = WriteByteToWav (SUPT_END, order, mode ) ;
                 if (error != ERR_OK) break ;
 
-                ptrFile->count = 0 ;
-                ptrFile->sum   = 0 ;
+                fileInfo.count = 0 ;
+                fileInfo.sum   = 0 ;
             }
             break ;
 
         case MODE_B11 :
-            if ( ptrFile->count >= BLK_OLD ) {
+            if ( fileInfo.count >= BLK_OLD ) {
 
-                if ( (ptrFile->debug & 0x0040) > 0 )
-                    debug_printf(" (%04X)", (uint) ptrFile->sum);
+                if ( (fileInfo.debug & 0x0040) > 0 )
+                    debug_printf(" (%04X)\n\r", (uint) fileInfo.sum);
                 /* Write the checksum */
-                error = WriteByteToWav (ptrFile->sum >> 8 & 0xFF, order, mode, ptrFile) ;
+                error = WriteByteToWav (fileInfo.sum >> 8 & 0xFF, order, mode ) ;
                 if (error != ERR_OK) break ;
-                error = WriteByteToWav (ptrFile->sum & 0xFF, order, mode, ptrFile) ;
+                error = WriteByteToWav (fileInfo.sum & 0xFF, order, mode ) ;
                 if (error != ERR_OK) break ;
 
-                error = WriteByteToWav (EOF_15, order, mode, ptrFile) ;
+                error = WriteByteToWav (EOF_15, order, mode ) ;
                 if (error != ERR_OK) break ;
-                if ( (ptrFile->debug & 0x0040) > 0) debug_printf(" (E:%02X)", (uint) EOF_15);
+                if ( (fileInfo.debug & 0x0040) > 0) debug_printf(" (E:%02X)", (uint) EOF_15);
                 writ_full_block = false ;
 
-                error = WriteSyncToWav (50, ptrFile) ; /* 0.02 s */
+                error = WriteSyncToWav (50 ) ; /* 0.02 s */
                 if (error != ERR_OK) break ;
-                error = WriteUsedatLenToQTWav (order, mode, ptrFile) ;
+                error = WriteUsedatLenToQTWav (order, mode ) ;
             }
             break ;
 
@@ -385,8 +377,7 @@
 
 /* File name for New and Old BASIC */
 int WriteSaveNameToWav (char*  ptrName,
-                        uchar  mode,
-                    FileInfo*  ptrFile)
+                        uchar  mode)
 {
      uint  ii ;
      uint  tmpL ;
@@ -394,7 +385,7 @@
      char  tmpS[20] ;
       int  error ;
 
-   if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG ptrName %s\n\r", ptrName);
+   if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG ptrName %s\n\r", ptrName);
 
     do {
         /* Uppercase the name is done in main if needed */
@@ -421,7 +412,7 @@
        for ( ii = 0 ; ii < tmpL ; ++ii )
             tmpS[ii] = 0 ;
 
-        if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG tmpS %s\n\r", tmpS);
+        if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG tmpS %s\n\r", tmpS);
         for ( ii = tmpL ; ii < 7 ; ++ii ) {
             byte = (ulong) ptrName[6 - ii] ;
 
@@ -430,9 +421,9 @@
             case MODE_B20 :
 
                 if (byte < 0x80)
-                    byte = CodeOld[byte] ;
+                    byte = (char)CodeOld[byte] ;
                 else
-                    byte = CodeOld[0] ;
+                    byte = (char)CodeOld[0] ;
                 break ;
 
             default :
@@ -446,28 +437,27 @@
         tmpS[7] = 0x5F ;
 
         /* Write the Name */
-        ptrFile->count = 0 ;
-        ptrFile->sum   = 0 ;
+        fileInfo.count = 0 ;
+        fileInfo.sum   = 0 ;
         for ( ii = 0 ; ii < 8 ; ++ii ) {
-            error = WriteByteSumToWav (tmpS[ii], ORDER_STD, mode, ptrFile) ;
+            error = WriteByteSumToWav (tmpS[ii], ORDER_STD, mode ) ;
             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) ;
+        if (fileInfo.ident == IDENT_PC1211)
+            error = WriteSyncToWav (151 ) ;
+        else if (fileInfo.ident == IDENT_PC121_DAT)
+            error = WriteSyncToWav (111 ) ;
 
-        ptrFile->count = 0 ;
-        ptrFile->sum   = 0 ;
+        fileInfo.count = 0 ;
+        fileInfo.sum   = 0 ;
 
     } while (0) ;
     return (error);
 }
 
 int DEBUGSaveNameToWav (char*  ptrName,
-                        uchar  mode,
-                    FileInfo*  ptrFile)
+                        uchar  mode)
 {
      uint  ii ;
      uint  i ;
@@ -521,9 +511,9 @@
             case MODE_B20 :
 
                 if (byte < 0x80)
-                    byte = CodeOld[byte] ;
+                    byte = (char)CodeOld[byte] ;
                 else
-                    byte = CodeOld[0] ;
+                    byte = (char)CodeOld[0] ;
                 break ;
 
             default :
@@ -538,25 +528,21 @@
         debug_printf("DEBUG ii %u\n\r", ii);
 
         /* Write the Name */
-        ptrFile->count = 0 ;
-        ptrFile->sum   = 0 ;
+        fileInfo.count = 0 ;
+        fileInfo.sum   = 0 ;
         for ( ii = 0 ; ii < 8 ; ++ii ) {
-            error = WriteByteSumToWav (tmpS[ii], ORDER_STD, mode, ptrFile) ;
+            error = WriteByteSumToWav (tmpS[ii], ORDER_STD, mode ) ;
             if (error != ERR_OK) break ;
         }
-        if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG Name - Bytes was printed swapped.\n\r");
-
-        debug_printf("DEBUG WriteSyncToWav prima\n\r");
+        if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG Name - Bytes was printed swapped.\n\r");
 
-        if (ptrFile->ident == IDENT_PC1211)
-            error = WriteSyncToWav (151, ptrFile) ;
-        else if (ptrFile->ident == IDENT_PC121_DAT)
-            error = WriteSyncToWav (111, ptrFile) ;
-        debug_printf("DEBUG WriteSyncToWav dopo\n\r");
+        if (fileInfo.ident == IDENT_PC1211)
+            error = WriteSyncToWav (151 ) ;
+        else if (fileInfo.ident == IDENT_PC121_DAT)
+            error = WriteSyncToWav (111 ) ;
 
-        ptrFile->count = 0 ;
-        ptrFile->sum   = 0 ;
-        debug_printf("DEBUG fine\n\r");
+        fileInfo.count = 0 ;
+        fileInfo.sum   = 0 ;
 
     } while (0) ;
     return (error);
@@ -565,8 +551,7 @@
 /* Head of Binary Data for New and Old series */
 int WriteHeadToBinWav (ulong  addr,
                        ulong  size,
-                       uchar  mode,
-                   FileInfo*  ptrFile)
+                       uchar  mode)
 {
       int  ii ;
     ulong  len ;
@@ -581,67 +566,67 @@
     }
     */
 
-        ptrFile->count = 0 ;
-        ptrFile->sum   = 0 ;
+        fileInfo.count = 0 ;
+        fileInfo.sum   = 0 ;
         for ( ii = 0 ; ii < 4 ; ++ii ) {
-            error = WriteByteSumToWav (0, ORDER_STD, mode, ptrFile) ;
+            error = WriteByteSumToWav (0, ORDER_STD, mode ) ;
             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) ;
+        error = WriteByteSumToWav (tmpL, ORDER_STD, mode ) ;
         if (error != ERR_OK) break ;
 
         tmpL = ((addr << 4) & 0xF0) + ((addr >> 4) & 0x0F) ;/* L swapped */
-        error = WriteByteSumToWav (tmpL, ORDER_STD, mode, ptrFile) ;
+        error = WriteByteSumToWav (tmpL, ORDER_STD, mode ) ;
         if (error != ERR_OK) break ;
 
         /* Write the Length */
         len = size - 1 ;
         tmpL = ((len >> 4) & 0xF0) + (len >> 12) ;
-        error = WriteByteSumToWav (tmpL, ORDER_STD, mode, ptrFile) ;
+        error = WriteByteSumToWav (tmpL, ORDER_STD, mode ) ;
         if (error != ERR_OK) break ;
 
         tmpL = ((len << 4) & 0xF0) + ((len >> 4) & 0x0F) ;
-        error = WriteByteSumToWav (tmpL, ORDER_STD, mode, ptrFile) ;
+        error = WriteByteSumToWav (tmpL, ORDER_STD, mode ) ;
         if (error != ERR_OK) break ;
 
-        ptrFile->count = 0 ;
-        ptrFile->sum   = 0 ;
+        fileInfo.count = 0 ;
+        fileInfo.sum   = 0 ;
 
     } while (0) ;
     return (error);
 }
 
-int WriteFooterToNewWav (FileInfo*  ptrFile)
+int WriteFooterToNewWav ( void )
 {
     int  error ;
 
     do {
-        ptrFile->count = 0 ; /* no checksum writing from here until the end */
+        fileInfo.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) ;
+        error = WriteByteSumToWav(BAS_NEW_EOF, ORDER_STD, fileInfo.mode ) ;
+        // error = WriteByteSumToB13Wav (BAS_NEW_EOF ) ;
         if (error != ERR_OK) break ;
 
-        error = WriteByteToWav(BAS_NEW_EOF, ORDER_STD, ptrFile->mode, ptrFile) ;
+        error = WriteByteToWav(BAS_NEW_EOF, ORDER_STD, fileInfo.mode ) ;
         if (error != ERR_OK) break ;
 
-        if ( (ptrFile->debug & 0x00C0) > 0 )
+        if ( (fileInfo.debug & 0x00C0) > 0 )
             debug_printf(" EOF:%02X", (uchar) BAS_NEW_EOF);
 
-        error = WriteByteToWav(ptrFile->sum, ORDER_STD, ptrFile->mode, ptrFile) ;
+        error = WriteByteToWav(fileInfo.sum, ORDER_STD, fileInfo.mode ) ;
         if (error != ERR_OK) break ;
 
-        if ( (ptrFile->debug & 0x0040) > 0 )
-            debug_printf(" (%02X)", (uchar) ptrFile->sum);
+        if ( (fileInfo.debug & 0x0040) > 0 )
+            debug_printf(" (%02X)", (uchar) fileInfo.sum);
 
     /* there are 2bits more HIGH at the end of transmission (at least for PC-1402) M. NOSSWITZ */
-     error = WriteBitToWav (1, ptrFile) ;
+     error = WriteBitToWav (1 ) ;
     if (error != ERR_OK) break ;
 
-    error = WriteBitToWav (1, ptrFile) ;
+    error = WriteBitToWav (1 ) ;
     if (error != ERR_OK) break ;
  
     /* This puts 2 bits of silence (or 2 HIGH bits alternatively) to the end of the wave file. */
@@ -650,9 +635,39 @@
     /* 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     */
     /* not needed for the MBed direct-write version
-    error = WriteBitToWav (3, ptrFile) ; 125us High , 
+    error = WriteBitToWav (3 ) ; 125us High , 
+    if (error != ERR_OK) break ;
+    error = WriteBitToWav (2 ) ; 1 ms Midsignal
     if (error != ERR_OK) break ;
-    error = WriteBitToWav (2, ptrFile) ; 1 ms Midsignal
+    */
+
+    } while (0) ;
+    return (error);
+}
+
+int WriteFooterToMemoWav ( void )
+{
+    int  error ;
+
+    do {
+        error = WriteByteToWav(fileInfo.sum, ORDER_STD, fileInfo.mode ) ;
+        if (error != ERR_OK) break ;
+
+        if ( (fileInfo.debug & 0x0040) > 0 )
+            debug_printf(" (%02X)", (uchar) fileInfo.sum);
+
+    error = WriteBitToWav (1 ) ;
+    if (error != ERR_OK) break ;
+
+    error = WriteBitToWav (1 ) ;
+    if (error != ERR_OK) break ;
+
+    /* This puts 2 bits of silence (or 2 HIGH bits alternatively) to the end of the wave file. */
+    /* not needed for the MBed send version
+    error = WriteBitToWav (3 ) ;
+    if (error != ERR_OK) break ;
+
+    error = WriteBitToWav (2 ) ;
     if (error != ERR_OK) break ;
     */
 
@@ -660,62 +675,47 @@
     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 )
-            debug_printf(" (%02X)", (uchar) ptrFile->sum);
-
-    error = WriteBitToWav (1, ptrFile) ;
-    if (error != ERR_OK) break ;
 
-    error = WriteBitToWav (1, ptrFile) ;
-    if (error != ERR_OK) break ;
+// File completion check
+bool isFileSendComplete ( void ) {
+#ifdef FILE_BUF_SIZE 
+    return ( isFilePullComplete() ) ;
+#else
+    return ( file_pos == BIN_FILE_SIZE - 1 ) ; 
+#endif
+}
 
-    /* This puts 2 bits of silence (or 2 HIGH bits alternatively) to the end of the wave file. */
-    /* not needed for the MBed send version
-    error = WriteBitToWav (3, ptrFile) ;
-    if (error != ERR_OK) break ;
-
-    error = WriteBitToWav (2, ptrFile) ;
-    if (error != ERR_OK) break ;
-    */
-
-    } while (0) ;
-    return (error);
+// Input file data access, depends on build
+char fileGetNext ( void ) {
+    // byte = fgetc (srcFd) ; // DOS / UNIX file - not applicable here 
+#ifdef FILE_BUF_SIZE 
+    return ( filePullData () ) ;
+#else
+    return ( bin_file_bytes[file_pos++] ); 
+#endif
 }
 
+
 /////////////////////////////////////////////////////////////////////////////
-// My file-send implementation
-// Inspired to Pocket-Tools source code ...
-int FileSend ( char* FileName, char* FileStream, uint FileSize, FileInfo*  ptrFile )
+// file-send implementation, largely inspired to Pocket-Tools source code
+int FileSend ( void )
 {
-    int      pcId  =  PC_ID; 
+    
+    int      pcId  =  PC_ID;  // hardcoded for PC-1403 here
+    uint32_t nbSync = N_SYNC_BITS; 
+    int      ii;
     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;
+    char     inVal;   
 
-    if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG FileName %s\n\r",FileName);
-    if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG ptrFile->ident %u\n\r",ptrFile->ident);
-    if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG nbSync %u\n\r",nbSync);
-    if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG nbByte %u\n\r",nbByte);
+    fileInfo.nbSync = nbSync;
+#ifndef FILE_BUF_SIZE 
+    file_pos = 0;
+#endif
 
-    switch (ptrFile->ident) {
+    switch (fileInfo.ident) {
     /* . . .*/
         case IDENT_NEW_BIN :
             pcgrpId = GRP_NEW ; /*or GRP_EXT */
@@ -736,8 +736,8 @@
     }   
     else { //   PC-1211 to PC-1500, QTape 
     */   
-        if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG WriteSyncToWav\n\r");
-        error = WriteSyncToWav (nbSync, ptrFile) ;
+        if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG WriteSyncToWav\n\r");
+        error = WriteSyncToWav (nbSync ) ;
     /*
         . . .
     */
@@ -754,7 +754,7 @@
     */
         break;
     default :
-        debug_printf ("%s: Pocket computer %d is not implemented\n", argP, pcId) ;
+        debug_printf ("%s: Sharp PC-%d not implemented\n", argP, pcId) ;
         // MoreInfo (ERR_ARG);
         error = ERR_ARG ;
             // break ;
@@ -764,11 +764,11 @@
 /*  ...
     else { // PC-121x ... PC-1475 
 */
-    if ( (ptrFile->debug & 0x0040) > 0 ) 
-        debug_printf("DEBUG set Header Mode (ident %d)\n\r", ptrFile->ident);
-    switch (ptrFile->ident) { /* Header Mode */
+    if ( (fileInfo.debug & 0x0040) > 0 ) 
+        debug_printf("DEBUG set Header Mode (ident %d)\n\r", fileInfo.ident);
+    switch (fileInfo.ident) { /* Header Mode */
     case IDENT_PC1211 :
-        ptrFile->mode = ptrFile->mode_h = MODE_B20 ;
+        fileInfo.mode = fileInfo.mode_h = MODE_B20 ;
         break ;
 
     case IDENT_PC121_DAT :
@@ -776,7 +776,7 @@
     case IDENT_OLD_DAT :
     case IDENT_OLD_BIN :
     case IDENT_OLD_MEM :
-        ptrFile->mode = ptrFile->mode_h = MODE_B19 ;
+        fileInfo.mode = fileInfo.mode_h = MODE_B19 ;
         break ;
 
     case IDENT_NEW_TEL :
@@ -790,43 +790,43 @@
     case IDENT_EXT_BAS :
     case IDENT_NEW_DAT :
     case IDENT_NEW_BIN :
-        ptrFile->mode = ptrFile->mode_h = MODE_B16 ;
+        fileInfo.mode = fileInfo.mode_h = MODE_B16 ;
         break ;
 
     default :
         debug_printf ("%s: Unknown Ident\n", argP) ;
-        ptrFile->mode = ptrFile->mode_h = MODE_B21 ;
+        fileInfo.mode = fileInfo.mode_h = MODE_B21 ;
         return (ERR_ARG);
     }
-    if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG Header ptrFile->mode_h %u\n\r",ptrFile->mode_h);
+    if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG Header fileInfo.mode_h %u\n\r",fileInfo.mode_h);
 
     /* Write the TAPE code */
-    if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG Write the TAPE code\n\r");
-    error = WriteByteToWav ( (ulong) ptrFile->ident, ORDER_STD, ptrFile->mode_h, ptrFile) ;
+    if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG Write the TAPE code\n\r");
+    error = WriteByteToWav ( (ulong) fileInfo.ident, ORDER_STD, fileInfo.mode_h ) ;
     if (error != ERR_OK) return ( error )  ;
 
     /* Write the Name */
-    if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG Write the Name\n\r");
-    error = WriteSaveNameToWav ( FileName, ptrFile->mode_h, ptrFile) ;
-    if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG error (ERR_OK) %d (%d)\n\r", error, ERR_OK);
+    if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG Writing Name...\n\r");
+    error = WriteSaveNameToWav ( "NONAME", fileInfo.mode_h ) ; // NOT USING FILENAME !!
+    if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG error (ERR_OK) %d (%d)\n\r", error, ERR_OK);
     if (error != ERR_OK) return ( error )  ;
-
-    if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG set Body Data Mode\n\r");
-    switch (ptrFile->ident) { /* Body Data Mode */
+    
+    if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG set Body Data Mode\n\r");
+    switch (fileInfo.ident) { /* Body Data Mode */
         case IDENT_PC1211 :
-            ptrFile->mode = MODE_B20 ;
+            fileInfo.mode = MODE_B20 ;
             break ;
     
         case IDENT_PC121_DAT :
         case IDENT_OLD_BAS :
         case IDENT_OLD_BIN :
         case IDENT_OLD_MEM :
-            ptrFile->mode = MODE_B19 ;
+            fileInfo.mode = MODE_B19 ;
             break ;
     
         case IDENT_OLD_DAT :
         case IDENT_NEW_DAT :
-            ptrFile->mode = MODE_B15 ;
+            fileInfo.mode = MODE_B15 ;
         break ;
     
         case IDENT_EXT_BAS :
@@ -840,80 +840,76 @@
         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*/
+            if (cnvstr_upr && pcId < 1440) fileInfo.mode = MODE_B13 ; /*older part of new series*/
+            else  fileInfo.mode = MODE_B14 ;     /*new series and extended series*/
             break ;
     
         default :
             debug_printf ("%s: Unknown Ident\n", argP) ;
             return ( ERR_ARG );
         }
-        if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG Body ptrFile->mode %u\n\r", ptrFile->mode);
+        if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG Body fileInfo.mode %u\n\r", fileInfo.mode);
 
-        ptrFile->total = 0 ; /* count bytes of body only */
+        fileInfo.total = 0 ; /* count bytes of body only */
                 
-        switch (ptrFile->ident) { /* header was written, write all data now */
+        switch (fileInfo.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 ) debug_printf("DEBUG Write the datas\n\r");
+            if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG Writing data...\n\r");
             /* Write the datas */
-//            info.mode = MODE_B13 ; /*PC-1403 and newer should be MODE_14 */
+//            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 ) debug_printf("DEBUG LOOP ii %u\n\r", ii);
-
-                inVal = FileStream[ii] ; // fgetc (srcFd) ;
-                if ( inVal == EOF ) break ; // premature ending shouldn't happen...
-
+            while  ( !isFileSendComplete() ) {
+                inVal = fileGetNext();
+                if ( inVal == EOF ) break ; // ending if 
                 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) ;
+                    if (fileInfo.count + 1 == BLK_NEW && fileInfo.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, fileInfo.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 ) {
+                        if ((fileInfo.debug & 0x800) == 0 ) {
                             error = ERR_SUM ;
                             break ;
                         }
                     }
                 }
-                error = WriteByteSumToWav ( (uint) inVal, ORDER_STD, ptrFile->mode, ptrFile) ;
+                error = WriteByteSumToWav ( (uint) inVal, ORDER_STD, fileInfo.mode ) ;
                 if (error != ERR_OK) break ;
             }
             if (error != ERR_OK) break ;
-            if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("\n\rDEBUG ii %u\n\r", ii);
-
-            inVal = FileStream[ii] ; // fgetc (srcFd) ; /* Read the last byte before EOF mark */
-            if (inVal == EOF) break ;
+            if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("\n\rDEBUG ii %u\n\r", ii);
 
+            inVal = fileGetNext(); /* 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 */
+                /* 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 ) debug_printf("DEBUG last byte: %02X\n\r", (uchar) inVal);
-                error = WriteByteToWav ( (uint) inVal, ORDER_STD, ptrFile->mode, ptrFile) ;
+                if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG last byte: %02X\n\r", (uchar) inVal);
+                error = WriteByteToWav ( (uint) inVal, ORDER_STD, fileInfo.mode ) ;
                 if (error != ERR_OK) break ;
-                CheckSumB1 ((uint) inVal, ptrFile) ; /* never write the checksum before BAS_NEW_EOF */
+                CheckSumB1 ((uint) inVal ) ; /* never write the checksum before BAS_NEW_EOF */
 
-                ++ptrFile->total ;
-                ++ptrFile->count ; /* for debug purposes only, WriteFooter will reset it */
+                ++fileInfo.total ;
+                ++fileInfo.count ; /* for debug purposes only, WriteFooter will reset it */
             }
 
             /* Write the END code */
-            if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG WriteFooterToNewWav\n\r");
-            error = WriteFooterToNewWav (ptrFile) ;
+            if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG WriteFooterToNewWav\n\r");
+            error = WriteFooterToNewWav ( ) ;
 
             break ; // IDENT_NEW_BAS, IDENT_EXT_BAS
 
         case IDENT_NEW_BIN :
             /* Write the address and length */
-            error = WriteHeadToBinWav (addr, nbByte, ptrFile->mode_h, ptrFile) ;
+            error = WriteHeadToBinWav (addr, nbByte, fileInfo.mode_h ) ;
             if (error != ERR_OK) break ;
             /* no break */
 
@@ -923,28 +919,28 @@
         case IDENT_NEW_CRD :
 
             /* Write the datas */
-            for ( ii = 0 ; ii < nbByte - 1 ; ++ii ) {
-                inVal = FileStream[ii] ; // fgetc (srcFd) ;
-                if (inVal == EOF) break ; // premature ending shouldn't happen ...
+            while  ( !isFileSendComplete() ) {
+                inVal = fileGetNext();
+                if (inVal == EOF ) break ; // premature ending shouldn't happen ...
 
-                error = WriteByteSumToWav ( (uint) inVal, ORDER_STD, ptrFile->mode, ptrFile) ;
+                error = WriteByteSumToWav ( (uint) inVal, ORDER_STD, fileInfo.mode ) ;
                 if (error != ERR_OK) break ;
             }
             if (error != ERR_OK) break ;
 
-            inVal = FileStream[ii] ; // fgetc (srcFd) ; /* Read the last byte before EOF mark */
+            inVal = fileGetNext();
             if (inVal == EOF) break ;
 
-            if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG %02X", (uchar) inVal);
-            error = WriteByteToWav ( (uint) inVal, ORDER_STD, ptrFile->mode, ptrFile) ;
+            if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG %02X", (uchar) inVal);
+            error = WriteByteToWav ( (uint) inVal, ORDER_STD, fileInfo.mode ) ;
             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 */
+            CheckSumB1 ( (uint) inVal  ) ; /* never write the checksum before BAS_NEW_EOF */
+            ++fileInfo.total ;
+            ++fileInfo.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 ) ;
+            if ( fileInfo.ident == IDENT_NEW_BIN) error = WriteFooterToNewWav ( ) ;
+            else WriteFooterToMemoWav ( ) ;
 
             break ; // IDENT_NEW_BIN and IDENT_NEW_Memos
         default:
@@ -953,7 +949,7 @@
             break;
         }        
 
-    if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("\n\rDEBUG FileSend error %d\n\r", error);
     return (error);
 
-}
\ No newline at end of file
+}
+