Commodore disk image .NET library

Started by xlar54, December 19, 2007, 03:42 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

xlar54

Hey guys,

Im working on a CBM disk image .NET library written in C#.  The signature for the methods currently are:

namespace CBMDiskImage
{
    interface IDiskImage
    {
        bool LoadImage(string filename);
        bool SaveImage(string filename);
        void FormatImage(string name, string ID);
        List GetDirectoryEntries();

        DriveStatus LoadFile(string filename, out byte[] data);
        DriveStatus RenameFile(string originalName, string newName);
        DriveStatus CopyFile(string srcFile, string destFile);
        DriveStatus SaveFile(string filename, byte[] fileData);
        DriveStatus DeleteFile(string filename);
    }
}

Right now, it works with D64 images, but I hope to add D71 and D81 images once its complete.  For the D64 images, CopyFile() and SaveFile() still need work... the BAM allocation and such.

Anyone who has written anything like this knows how somewhat complicated this part is (the BAM stuff).  My initial jump into the BAM was the completion of the Delete() method, and its working quite well, so Im on the right track I think.

Are there any other .NET developers out there who might be interested in jumping in on this project?  Thus far, Ive seen Java code as C code for these things, but nothing as of yet for .NET languages. Let me know and we will find a place to host this.  Maybe Lance could set up something while its in development and then we could later move it to sourceforge.

hydrophilic

Now that's a can of worms!  There is an open source program called D64 Lister or D64Edit -- sorry I don't have a link handy at the moment.  Anyway, its not .NET but is VisualBasic.  It originaly worked with .d64 and .t64 images and only PRG/SEQ files.

I modified it to work with .d71 and .d81 images plus added support for GEOS disks and files.  Maybe also REL files.  I contacted the author about working together but he took a while to respond and said he was too busy to work on it.  So I haven't done much with it since.

If you're interested in the code, I can make it available.  Of course VB to C# conversion may be more trouble than its worth...

Stephane Richard

I could probably translate it too.  if you can make it  available :-)...
When God created light, so too was born, the first Shadow!

MystikShadows

xlar54

Hey Im all for any code that might help.  As you may have guessed, the original intent is to have a reusable library because the bigger project is to write an application much like you are describing.  I figured I would start with the disk image library first and get it out of the way. So absolutely - whatever you have would be very useful indeed.  

I kinda wish the author of 64copy would open source it up, as there has to be tons of information in there that would be useful, and would allow for a native Windows port.  

Even so, Im learning a great deal about the Commodore drives just by writing this code from scratch, as well as doing some interesting coding anyway.  (At my work place, Ive moved out more towards managing development teams and dont get to flex the coding skill so much anymore... lol, must mean I wasnt that good ;)  )

hydrophilic

OK, I'll get my version uploaded for you.  In the meantime, the original is called D64 Editor by Forrest Mook and is available here.

xlar54

Hey, I was looking at Sourceforge for a resting place for the code.  I noticed that someone by the name of "path0s" already has a project out there. Ive talked to path0s in the past, but its been awhile.  Is path0s here on this site under a different name perhaps?  He didnt have any files submitted yet, so I figured if he hasn't made any progress, perhaps this would be a good start.  The code is working well with D64 images and can do all of the items listed in the interface listed above. A link to his project is here:

http://sourceforge.net/projects/cbmdisklib/

If anyone knows this person, let me know. Thanks!

airship

Golan knows him, I'm sure. Golan knows everybody.
Serving up content-free posts on the Interwebs since 1983.
History of INFO Magazine

Golan Klinger

I haven't heard from path0s in about a year and a half. You could try emailing him. His address is (or was) pathos at c64.org.
Call me Golan; my parents did.

airship

Serving up content-free posts on the Interwebs since 1983.
History of INFO Magazine

xlar54

A year and a half?!? Boy those Commodore-backsliders... we need to go to his house and preach the gospel to him... ;)

Thanks Golan - ill see if I can reach him that way.

hydrophilic

#10
My version of D64 Editor, umm lets call it D64+, is available here.

The D71, D81, GEOS, and REL support is read-only.  It does correctly scan the disk image to trace file streams and calculate BAM use (and detect corruption like chain loops) but the routines that write the disk image are still hard-code for D64.

If you compare this version with the original, you should find that over a dozen global arrays have been compressed into 2 arrays: sBlocks and sDirents.  Each is a custom VB Type, like a C struct.

Also a lot of magic numbers were replaced with named constants and functions were added to reduce repeated code.

But there are about a million things you could still do to improve this program.  I haven't really touched it since back in February or so when I emailed Forrest Mook.  This is due to several unanswered questions... without knowing for sure I figured it best not to proceed.

If you have any questions, I'll answer what I can.

I guess the basic operation is like this:

clear all sDirents and sBlocks
open disk image
based on file size, determine disk type and start of directory
scan directory:
  for each entry, scan all streams (data, VLIR, side-sector, and/or GEOS info)
  while scanning update corresponding sBlock() and note any cross-links or loops
repeat until end-of directory or loop detected
if C128 boot sector, check for additional allocated sectors
check header and BAM
note any 'problems'
display list of sDirents()

You can view the BAM in edit mode or in File Trace mode (this shows which blocks belong to a file).  The BAM viewer is basically a GUI for sBlocks().  Clicking a block opens a HEX/ASCII sector editor.

You can select properties for a file.  This is basically a GUI for sDirents().  It shows name, size (in blocks), file data / VLIR block start, CBM file type, GEOS file type, REL length / GEOS structure, and Date/Time Stamp.

Although REL and VLIR files are correctly parsed, the GUI is quite useless since it doesn't list the records for viewing/editing.

almightyc64

Hi everyone, I'm the author of the D64 Editor at http://almighty.c64.org/d64editor.html that was mentioned earlier in the thread.  It's written in Visual Basic 5 and the entire source is available under the GNU GPL.  I encourage anyone to use it to produce something even better :)  

If there are any questions I can answer about it I will be happy to do so.  Programming is not my day job so the code may not be logical to people who regularly do programming, but it is logical to me :)  

Anyway, if there is anything I can do to assist with anyone else's project I'll be happy to try.

Thanks!
Forrest

airship

Welcome, Forrest!

Where are you located in Iowa? I'm in Iowa City.
Serving up content-free posts on the Interwebs since 1983.
History of INFO Magazine

almightyc64

Hi Mark/Airship!  You live very close to me, only about an hour drive.  I'm in the Quad Cities and in fact I used to live in Iowa City in the mid 90s when I was attending the University of Iowa.  Nice to find another Iowan that is still interested in the Commodore :)

Forrest

airship

Well, I used to live in the Quad Cities, so we're even! :)
Serving up content-free posts on the Interwebs since 1983.
History of INFO Magazine

hydrophilic

Good to see you here Forrest.

I wanted to say another good place for this sort of software is the VICE program C1541.  Since it's in C and comes with a Visual Studio project workspace, it may be the easiest to translate into a .NET library.

bacon

And then there's of course MagerValp's disk image library in C, diskimage.c, used in CGTerm, D64scan, and DiskImagery64.
Bacon
-------------------------------------------------------
Das rubbernecken Sichtseeren keepen das cotton-pickenen Hands in die Pockets muss; relaxen und watschen die Blinkenlichten.

xlar54

Yes, I went through that code, but unfortunately, a direct C to C# conversion is rather difficult since C isnt object oriented and is pointer dependant. Still very good code though!