Skip to content

Commit

Permalink
Merge pull request #82 from craigthomas/extract-cas-to-disk
Browse files Browse the repository at this point in the history
Ability to extract `CAS` to `DSK` and `DSK` to `CAS`
  • Loading branch information
craigthomas authored Oct 9, 2022
2 parents e8dd5fd + 46437c1 commit 9fb0757
Show file tree
Hide file tree
Showing 9 changed files with 795 additions and 565 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ that are available:

* `--print` - prints out the assembled statements
* `--symbols` - prints out the symbol table
* `--bin_file` - save assembled contents to a binary file
* `--cas_file` - save assembled contents to a cassette file
* `--dsk_file` - save assembled contents to a virtual disk file
* `--to_bin` - save assembled contents to a binary file
* `--to_cas` - save assembled contents to a cassette file
* `--to_dsk` - save assembled contents to a virtual disk file
* `--name` - saves the program with the specified name on a cassette or virtual disk file

---
Expand Down Expand Up @@ -240,9 +240,9 @@ The columns are as follows:

### Save to Binary File

To save the assembled contents to a binary file, use the `--bin_file` switch:
To save the assembled contents to a binary file, use the `--to_bin` switch:

python3 assembler.py test.asm --bin_file test.bin
python3 assembler.py test.asm --to_bin test.bin

The assembled program will be saved to the file `test.bin`. Note that this file
may not be useful on its own, as it does not have any meta information about
Expand All @@ -255,9 +255,9 @@ will not have any effect on the assembled file).

### Save to Cassette File

To save the assembled contents to a cassette file, use the `--cas_file` switch:
To save the assembled contents to a cassette file, use the `--to_cas` switch:

python3 assembler.py test.asm --cas_file test.cas
python3 assembler.py test.asm --to_cas test.cas

This will assemble the program and save it to a cassette file called `test.cas`.
The source code must include the `NAM` mnemonic to name the program (e.g.
Expand All @@ -268,7 +268,7 @@ The source code must include the `NAM` mnemonic to name the program (e.g.
not be overwritten. If you wish to add the program to `test.cas`, you must
specify the `--append` flag during assembly:

python3 assembler.py test.asm --cas_file test.cas --append
python3 assembler.py test.asm --to_cas test.cas --append

To load from the cassette file, you must use BASIC's `CLOADM` command as follows:

Expand All @@ -278,9 +278,9 @@ To load from the cassette file, you must use BASIC's `CLOADM` command as follows

### Save to Disk File

To save the assembled contents to a disk file, use the `--dsk_file` switch:
To save the assembled contents to a disk file, use the `--to_dsk` switch:

python3 assembler.py test.asm --dsk_file test.dsk
python3 assembler.py test.asm --to_dsk test.dsk

This will assemble the program and save it to a disk file called `test.dsk`.
The source code must include the `NAM` mnemonic to name the program on disk (e.g.
Expand All @@ -291,7 +291,7 @@ The source code must include the `NAM` mnemonic to name the program on disk (e.g
not be updated. If you wish to add the program to `test.dsk`, you must specify the
`--append` flag during assembly:

python3 assembler.py test.asm --dsk_file test.dsk --append
python3 assembler.py test.asm --to_dsk test.dsk --append

To load from the disk file, you must use Disk Basic's `LOADM` command as follows:

Expand Down
18 changes: 9 additions & 9 deletions assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ def parse_arguments():
help="print out the assembled statements when finished"
)
parser.add_argument(
"--bin_file", metavar="BIN_FILE", help="stores the assembled program in a binary BIN_FILE"
"--to_bin", metavar="BIN_FILE", help="stores the assembled program in a binary BIN_FILE"
)
parser.add_argument(
"--cas_file", metavar="CAS_FILE", help="stores the assembled program in a cassette image CAS_FILE"
"--to_cas", metavar="CAS_FILE", help="stores the assembled program in a cassette image CAS_FILE"
)
parser.add_argument(
"--dsk_file", metavar="DSK_FILE", help="stores the assembled program in a disk image DSK_FILE"
"--to_dsk", metavar="DSK_FILE", help="stores the assembled program in a disk image DSK_FILE"
)
parser.add_argument(
"--name", help="the name of the file to be created on the cassette or disk image"
Expand Down Expand Up @@ -107,10 +107,10 @@ def main(args):
for statement in program.get_statements():
print(statement)

if args.bin_file:
if args.to_bin:
try:
virtual_file = VirtualFile(
SourceFile(args.bin_file, file_type=SourceFileType.BINARY),
SourceFile(args.to_bin, file_type=SourceFileType.BINARY),
VirtualFileType.BINARY
)
virtual_file.open_virtual_file()
Expand All @@ -120,13 +120,13 @@ def main(args):
print("Unable to save binary file:")
print(error)

if args.cas_file:
if args.to_cas:
if not coco_file.name:
print("No name for the program specified, not creating cassette file")
return
try:
virtual_file = VirtualFile(
SourceFile(args.cas_file, file_type=SourceFileType.BINARY),
SourceFile(args.to_cas, file_type=SourceFileType.BINARY),
VirtualFileType.CASSETTE
)
virtual_file.open_virtual_file()
Expand All @@ -136,13 +136,13 @@ def main(args):
print("Unable to save cassette file:")
print(error)

if args.dsk_file:
if args.to_dsk:
if not coco_file.name:
print("No name for the program specified, not creating disk file")
return
try:
virtual_file = VirtualFile(
SourceFile(args.dsk_file, file_type=SourceFileType.BINARY),
SourceFile(args.to_dsk, file_type=SourceFileType.BINARY),
VirtualFileType.DISK
)
virtual_file.open_virtual_file()
Expand Down
Loading

0 comments on commit 9fb0757

Please sign in to comment.