Skip to content
This repository was archived by the owner on Jan 18, 2024. It is now read-only.

Commit ad5a76e

Browse files
committed
Add final_address argument to make_sav
1 parent d299ffc commit ad5a76e

File tree

5 files changed

+42
-33
lines changed

5 files changed

+42
-33
lines changed

docs.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,17 @@ Output resulting file to `filename`, or to compilable-file-without-mac-extension
224224

225225
Output resulting file with binary header to `filename`, or to compilable-file-without-mac-extension + `.bin` if filename is not passed.
226226

227-
### `make_sav [/filename/]`
227+
### `make_sav [/filename/ [, final_address]]`
228228

229229
Output resulting file with `.sav` header to `filename`, or to compilable-file-without-mac-extension + `.sav` if filename is not passed.
230230

231-
### `make_turbo_wav [/filename/ [/title/]]`
231+
### `make_turbo_wav [/filename/ [, /title/]]`
232232

233233
Output resulting file in turbo wav format (see [this zx-pk.ru topic](https://zx-pk.ru/threads/30390-zagruzka-s-iphone-na-bk-0010-v-8-raz-bystree.html)) to `filename`, or to compilable-file-without-mac-extension + `.wav` if filename is not passed. If `title` is passed as well, it's the name of the file read by BK.
234234

235235
**If the filename equals `~speaker`, the file is played via speakers. Notice that this might not work correctly on Linux: you might get a segfault. `python3.6` from Ubuntu Bionic works for sure.**
236236

237-
### `make_wav [/filename/ [/title/]]`
237+
### `make_wav [/filename/ [, /title/]]`
238238

239239
Output resulting file in classic wav format (see [this zx-pk.ru topic](https://zx-pk.ru/threads/30298-zagruzka-s-magnitofona-na-bk-0011%28m%29.html)) to `filename`, or to compilable-file-without-mac-extension + `.wav` if filename is not passed. If `title` is passed as well, it's the name of the file read by BK.
240240

pdpy11/__main__.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,15 @@
8787
print(""" resulting filename. """)
8888
print("""make_bk0010_rom ["..."] / Same as --bin. If string is passed, this is the """)
8989
print("""make_bin ["..."] resulting filename. """)
90-
print("""make_sav ["..."] Same as --sav. If string is passed, this is the """)
91-
print(""" resulting filename. """)
92-
print("""make_turbo_wav ["..." ["..."]] Same as --turbo-wav. If a string is passed, this""")
90+
print("""make_sav ["..."[, ...]] Same as --sav. If string is passed, this is the """)
91+
print(""" resulting filename. If an additional argument """)
92+
print(""" is passed, it is the final address used by the """)
93+
print(""" program. """)
94+
print("""make_turbo_wav ["..."[, "..."]] Same as --turbo-wav. If a string is passed, this""")
9395
print(""" is the resulting filename. If two strings are """)
9496
print(""" passed, the first one is the real filename and """)
9597
print(""" the second one is BK filename. """)
96-
print("""make_wav ["..." ["..."]] Same as --wav. If a string is passed, this is """)
98+
print("""make_wav ["..."[, "..."]] Same as --wav. If a string is passed, this is """)
9799
print(""" the resulting filename. If two strings are """)
98100
print(""" passed, the first one is the real filename and """)
99101
print(""" the second one is BK filename. """)
@@ -307,9 +309,9 @@
307309
if project is not None:
308310
# Project mode
309311
lstname = project
310-
for ext, file, output, link_address in compiler.buildProject():
312+
for ext, file, args, output, link_address in compiler.buildProject():
311313
with open_device(file, "wb") as f:
312-
f.write(encodeBinRawSavWav(ext, output, link_address))
314+
f.write(encodeBinRawSavWav(ext, args, output, link_address))
313315
else:
314316
# Single file mode
315317
lstname = files[0]
@@ -321,14 +323,14 @@
321323

322324
out_files = compiler.link()
323325

324-
for ext, file in out_files:
326+
for ext, file, args in out_files:
325327
with open_device(file, "wb") as f:
326-
f.write(encodeBinRawSavWav(ext, compiler.output, compiler.link_address))
328+
f.write(encodeBinRawSavWav(ext, args, compiler.output, compiler.link_address))
327329

328330
if len(out_files) == 0:
329331
# No output file
330332
with open_device(output, "wb") as f:
331-
f.write(encodeBinRawSavWav(output_format or "bin", compiler.output, compiler.link_address))
333+
f.write(encodeBinRawSavWav(output_format or "bin", (), compiler.output, compiler.link_address))
332334

333335
if do_lst:
334336
with open(lstname + ".lst", "w") as f:

pdpy11/compiler/compiler.py

+17-16
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ def buildProject(self):
122122
self.addFile(file)
123123

124124
# Save all writes
125-
for ext, name in self.build:
125+
for ext, name, args in self.build:
126126
try:
127127
link_address = Deferred(self.link_address, int)(self)
128128
print(" Output: {name} ({ext} format) from {link}".format(name=name, ext=ext, link=util.octal(link_address)))
129129
except:
130130
print(" Output: {name} ({ext} format) from {link}".format(name=name, ext=ext, link=repr(self.link_address)))
131131

132-
self.all_build.append((ext, name, self.writes, self.link_address))
132+
self.all_build.append((ext, name, args, self.writes, self.link_address))
133133

134134
print("Linking")
135135
return self.link()
@@ -170,7 +170,7 @@ def link(self):
170170

171171
if self.project is not None:
172172
all_build = []
173-
for ext, file, writes, link_address in self.all_build:
173+
for ext, file, args, writes, link_address in self.all_build:
174174
array = []
175175
for addr, value in writes:
176176
value = Deferred(value, any)(self)
@@ -185,7 +185,7 @@ def link(self):
185185
array[addr + i] = value1
186186

187187
link_address = Deferred(link_address, int)(self)
188-
all_build.append((ext, file, array[link_address:], link_address))
188+
all_build.append((ext, file, tuple(Deferred(arg)(self) for arg in args), array[link_address:], link_address))
189189

190190
return all_build
191191
else:
@@ -204,7 +204,7 @@ def link(self):
204204

205205
self.link_address = Deferred(self.link_address, int)(self)
206206
self.output = array[self.link_address:]
207-
return self.build
207+
return [(ext, name, tuple(Deferred(arg)(self) for arg in args)) for ext, name, args in self.build]
208208

209209
def compileFile(self, file, code):
210210
parser = Parser(file, code, syntax=self.syntax)
@@ -307,7 +307,7 @@ def stringToCharlist(string):
307307
arg = arg[:-4]
308308
else:
309309
arg = os.path.join(os.path.dirname(parser.file), arg)
310-
self.build.append(("raw", arg))
310+
self.build.append(("raw", arg, ()))
311311
elif command == ".MAKE_BIN":
312312
if parser.file == self.include_root:
313313
if arg is None:
@@ -317,17 +317,18 @@ def stringToCharlist(string):
317317
arg += ".bin"
318318
else:
319319
arg = os.path.join(os.path.dirname(parser.file), arg)
320-
self.build.append(("bin", arg))
320+
self.build.append(("bin", arg, ()))
321321
elif command == ".MAKE_SAV":
322322
if parser.file == self.include_root:
323-
if arg is None:
324-
arg = parser.file
325-
if arg.lower().endswith(".mac"):
326-
arg = arg[:-4]
327-
arg += ".sav"
323+
filename, final_address = arg
324+
if filename is None:
325+
filename = parser.file
326+
if filename.lower().endswith(".mac"):
327+
filename = filename[:-4]
328+
filename += ".sav"
328329
else:
329-
arg = os.path.join(os.path.dirname(parser.file), arg)
330-
self.build.append(("sav", arg))
330+
filename = os.path.join(os.path.dirname(parser.file), filename)
331+
self.build.append(("sav", filename, (final_address,) if final_address is not None else ()))
331332
elif command == ".MAKE_TURBO_WAV" or command == ".MAKE_WAV":
332333
if parser.file == self.include_root:
333334
real_filename, bk_filename = arg
@@ -342,8 +343,8 @@ def stringToCharlist(string):
342343
bk_filename = os.path.basename(real_filename)
343344
if bk_filename.endswith(".wav"):
344345
bk_filename = bk_filename[:-4]
345-
pref = "turbo-wav:" if command == ".MAKE_TURBO_WAV" else "wav:"
346-
self.build.append((pref + bk_filename, real_filename))
346+
format = "turbo-wav" if command == ".MAKE_TURBO_WAV" else "wav"
347+
self.build.append((format, real_filename, (bk_filename,)))
347348
elif command == ".CONVERT1251TOKOI8R":
348349
pass
349350
elif command == ".DECIMALNUMBERS":

pdpy11/compiler/parser.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,12 @@ def handleMakeBin(self):
329329

330330
def handleMakeSav(self):
331331
with Transaction(self, maybe=False, stage=".MAKE_SAV"):
332-
return ".MAKE_SAV", self.needString(maybe=True)
332+
filename = self.needString(maybe=True)
333+
if filename is not None and self.needPunct(",", maybe=True):
334+
final_address = self.needExpression()
335+
else:
336+
final_address = None
337+
return ".MAKE_SAV", (filename, final_address)
333338

334339
def handleMakeTurboWav(self):
335340
with Transaction(self, maybe=False, stage=".MAKE_TURBO_WAV"):

pdpy11/compiler/util.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from .turbowav import encodeTurboWav
66
from .wav import encodeWav
77

8-
def encodeBinRawSavWav(output_format, raw, link_address):
8+
def encodeBinRawSavWav(output_format, args, raw, link_address):
99
if output_format == "bin":
1010
raw = [
1111
link_address & 0xFF,
@@ -14,8 +14,9 @@ def encodeBinRawSavWav(output_format, raw, link_address):
1414
len(raw) >> 8
1515
] + raw
1616
elif output_format == "sav":
17+
final_address = args[0] if len(args) >= 1 else link_address + len(raw)
1718
block_start = link_address // 512
18-
block_end = (link_address + len(raw) + 511) // 512
19+
block_end = (final_address + 511) // 512
1920
raw = [0] * 32 + [
2021
link_address & 0xFF,
2122
link_address >> 8,
@@ -25,8 +26,8 @@ def encodeBinRawSavWav(output_format, raw, link_address):
2526
0,
2627
0,
2728
0,
28-
(link_address + len(raw)) & 0xFF,
29-
(link_address + len(raw)) >> 8
29+
final_address & 0xFF,
30+
final_address >> 8
3031
] + [0] * 198 + [
3132
sum(((block_start <= ((7 - j) + i * 8) < block_end) << j for j in range(8)))
3233
for i in range(16)

0 commit comments

Comments
 (0)