-
Notifications
You must be signed in to change notification settings - Fork 0
/
SSD2UEF.py
executable file
·102 lines (79 loc) · 2.94 KB
/
SSD2UEF.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python
"""
Copyright (C) 2015 David Boddie <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
__author__ = "David Boddie <[email protected]>"
__date__ = "2019-05-05"
__version__ = "0.3"
__license__ = "GNU General Public License (version 3 or later)"
import sys
from tools import makedfs, UEFfile
if __name__ == "__main__":
args = sys.argv[:]
if "-s" in args:
at = args.index("-s")
strip_prefix = args[at + 1]
args = args[:at] + args[at + 2:]
else:
strip_prefix = "$."
if not 3 <= len(args) <= 4:
sys.stderr.write("Usage: %s <ssd file> <uef file> [file0,...]\n" % args[0])
sys.stderr.write("Usage: %s -l <ssd file>\n" % args[0])
sys.exit(1)
if args[1] == "-l":
print_catalogue = True
ssd_file = args[2]
else:
print_catalogue = False
ssd_file = args[1]
uef_file = args[2]
cat = makedfs.Catalogue(open(ssd_file))
if ssd_file.endswith(".dsd"):
cat.interleaved = True
title, disk_files = cat.read()
if print_catalogue:
max_length = 0
for file in disk_files:
max_length = max(max_length, len(repr(file.name)))
print repr(title)
for file in disk_files:
spacing = " " * (max_length - len(repr(file.name)))
print repr(file.name), spacing + "%08x %08x %x" % (
file.load_address, file.execution_address, file.length)
sys.exit()
if len(args) == 4:
names = args[3].split(",")
else:
names = []
for file in disk_files:
names.append(file.name)
index = {}
for file in disk_files:
index[file.name] = file
files = []
for name in names:
try:
file = index[name]
except KeyError:
sys.stderr.write("File '%s' not found in the disk catalogue.\n" % name)
sys.exit(1)
if name.startswith(strip_prefix):
name = name.lstrip(strip_prefix)
info = (name, file.load_address, file.execution_address, file.data)
files.append(info)
u = UEFfile.UEFfile(creator = "SSD2UEF.py " + __version__)
u.minor = 6
u.target_machine = "Electron"
u.import_files(0, files, gap = True)
u.write(uef_file, write_emulator_info = False)
sys.exit()