Page 1 of 1

Python module to create Acorn DFS .ssd images?

Posted: Mon Jul 31, 2017 9:38 pm
by SteveF
What I'm looking for is something I could use roughly as follows:

Code: Select all

import dfs
image = dfs.ssd()
image.set_title('Cool stuff')
image.add_file('$.!BOOT', "*BASIC\rCHAIN "MENU"\r", load=0x0000, exec=0x0000, locked=False)
image.add_file("$.MENU", open("menu.bas", "rb").read(), load=0x0000, exec=0x0000, locked=False)
open('myprog.ssd', 'wb').write(image.get())
I started knocking my own up, then realised how much I hated doing it. :-)

I found https://github.com/rcook/ssdtools which looks as though I could turn it into what I want, but it's not directly applicable as it's more of a command line tool. So before I start with that, I thought I'd ask if anyone has already done this.

I really need this to be under some kind of open source licence as well, I'm afraid. I'm building a command line driver for PLASMA and I'd like it to be able to take PLASMA source as input and emit an emulator-ready SSD at the other end, so I'd want to put the code in the PLASMA repository on github.

Sorry if this already exists and my searching powers were weak...

ETA: Not sure if this should be in the "utilities" forum instead, I'll leave it up to the moderators to advise...

Re: Python module to create Acorn DFS .ssd images?

Posted: Mon Jul 31, 2017 9:41 pm
by jgharston
I've never used Python, are you able to shell out and call another program, like system() or OSCLI? Then you could do something like system(path_to_mkimg$+"mkimg "+outfile$+" "+inlist$);

Re: Python module to create Acorn DFS .ssd images?

Posted: Mon Jul 31, 2017 9:44 pm
by SteveF
Python can do that, but I'm really looking for something self-contained if possible. Otherwise I guess I can use Richard's ssdtools directly by invoking them as you suggest.

Re: Python module to create Acorn DFS .ssd images?

Posted: Mon Jul 31, 2017 10:11 pm
by davidb
I have a couple of modules that do fairly limited things with DFS images, basically just to make it easier to create them and fill them with files. One place they can be found is in my UEF2ROM repository, though they could be broken out into a separate repository along with one or two tools I have that use them.

The API could be improved a bit. Here's a code snippet that puts a file in a disk image:

Code: Select all

import makedfs

disk = makedfs.Disk()
disk.new()

catalogue = disk.catalogue()
catalogue.boot_option = 3

disk_files = []
data, load, exec_ = "Some data", 0x1900, 0x1900
disk_files.append(makedfs.File("$.FILE", data, load, exec_, len(data)))

catalogue.write("Title", disk_files)

disk.file.seek(0, 0)
disk_data = disk.file.read()
open(out_file, "w").write(disk_data)

Re: Python module to create Acorn DFS .ssd images?

Posted: Mon Jul 31, 2017 10:16 pm
by SteveF
Thanks David, that looks great! I'll give it a go and let you know how I get on.

Re: Python module to create Acorn DFS .ssd images?

Posted: Mon Jul 31, 2017 11:29 pm
by jgharston
SteveF wrote:Python can do that, but I'm really looking for something self-contained if possible. Otherwise I guess I can use Richard's ssdtools directly by invoking them as you suggest.
That reads really oddly. Surely something like mkimg or ssdtools *is* self-contained. It is a single simple tool that does a single specific task, without you having to give it anything else. Changing to 'looking *to* *write* *something* self-contained...' makes it work. :)

I'm reminded of a discussion with a colleague at work yonks ago when he said "we need to use something proprietary, like HTML". Err, no... that's *non*-proprietary.

Re: Python module to create Acorn DFS .ssd images?

Posted: Tue Aug 01, 2017 1:27 am
by simonm
Maybe you could use BeebAsm? Just assemble a sourcefile containing a bunch of PUTFILE commands and no source and have it write the output SSD. Only snafu there is you can't set the title. Just a thought anyways.

Re: Python module to create Acorn DFS .ssd images?

Posted: Tue Aug 01, 2017 3:11 pm
by SteveF
Ha, I didn't express that very well, did I? What I was trying to say was that I'd like to avoid adding external dependencies to my Python program if I can help it. Ultimately I'd like to make it easy for someone to download a ready-to-go PLASMA development environment and the fewer external components I have to bundle or tell them to install separately the better.

@simonm Ta, that would work - I am in fact (mis)using beebasm for exactly this elsewhere in PLASMA at the moment, but I'd like to get away from that dependency if I can help it, so it looks like David's Python module will be perfect.