From 6127cbe9d12a6d62a706ccaf4aa910a8834169b0 Mon Sep 17 00:00:00 2001 From: Leeland Heins Date: Tue, 5 Mar 2019 07:14:07 -0600 Subject: [PATCH] Work on writing files --- ProDOS.pm | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/ProDOS.pm b/ProDOS.pm index 6b268b1..226fc36 100644 --- a/ProDOS.pm +++ b/ProDOS.pm @@ -1480,6 +1480,57 @@ sub write_file { $debug = 1 if defined $dbg && $dbg; print "pofile=$pofile filename=$filename mode=$mode conv=$conv apple_filename=$apple_filename\n" if $debug; + + return 0 if ! -e $filename; + + # Get size of input file + my $fsize = -s $filename; + print "fsize=$fsize\n"; + + my $numblocks = $fsize / 512 + (($fsize % 512) ? 1 : 0); + print "numblocks=$numblocks\n"; + + # Find an empty file descriptive entry in the proper subdirectory. + # May need to add a subdirectory block if the directory is full. + + # Read in the file. + my $ifh; + my $file_buffer; + if (open($ifh, "<$filename")) { + my $file_buffer = <$ifh>; + + my @bytes = unpack "C*", $file_buffer; + + if ($numblocks == 1) { + # Seedling file. + + # Get the block to use. + + # Write the single block + } elsif ($numblocks <= 256) { + # Sapling file. + + # Get the list of blocks to use. + + # Write out the index block. + + # Write out the data blocks. + } else { + # Tree file. + + # Get the list of blocks to use. + + # Create the master index block. + + # Create the subindex blocks. + + # Write out the data blocks. + } + } else { + return 0; + } + + return 1; } #