Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions src/zxbasm/zxbasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,24 @@
import argparse
import os
import sys
from enum import StrEnum

import src.api.config
from src.api import errmsg, global_
from src.api.config import OPTIONS
from src.api.errmsg import warning_command_line_flag_deprecation
from src.zxbasm import asmparse, expr
from src.zxbasm.version import VERSION
from src.zxbpp import zxbpp
from src.zxbpp.zxbpp import PreprocMode


class FileType(StrEnum):
BIN = "bin"
SNA = "sna"
TAP = "tap"
TZX = "tzx"
Z80 = "z80"


def main(args=None):
Expand Down Expand Up @@ -50,7 +61,8 @@ def main(args=None):
default=None,
)

o_parser.add_argument(
output_file_type_group = o_parser.add_mutually_exclusive_group()
output_file_type_group.add_argument(
"-T",
"--tzx",
action="store_true",
Expand All @@ -59,7 +71,7 @@ def main(args=None):
help="Sets output format to tzx (default is .bin)",
)

o_parser.add_argument(
output_file_type_group.add_argument(
"-t",
"--tap",
action="store_true",
Expand All @@ -68,6 +80,16 @@ def main(args=None):
help="Sets output format to tzx (default is .bin)",
)

output_file_type_group.add_argument(
"-f",
"--output-format",
type=str,
choices=[str(x) for x in FileType],
required=False,
help="Output format",
default=OPTIONS.output_file_type,
)

o_parser.add_argument(
"-B",
"--BASIC",
Expand Down Expand Up @@ -114,7 +136,6 @@ def main(args=None):

if not os.path.exists(options.PROGRAM):
o_parser.error("No such file or directory: '%s'" % options.PROGRAM)
sys.exit(2)

OPTIONS.debug_level = int(options.debug)
OPTIONS.input_filename = options.PROGRAM
Expand All @@ -127,10 +148,18 @@ def main(args=None):
OPTIONS.force_asm_brackets = options.bracket
OPTIONS.zxnext = options.zxnext

if options.tzx:
OPTIONS.output_file_type = "tzx"
if options.output_format:
OPTIONS.output_file_type = options.output_format
elif options.tzx:
OPTIONS.output_file_type = FileType.TZX
warning_command_line_flag_deprecation(
f"--tzx (use -f {FileType.TZX} or --output-format={FileType.TZX} instead)"
)
elif options.tap:
OPTIONS.output_file_type = "tap"
OPTIONS.output_file_type = FileType.TAP
warning_command_line_flag_deprecation(
f"--tap (use -f {FileType.TAP} or --output-format={FileType.TAP} instead)"
)

if not OPTIONS.output_filename:
OPTIONS.output_filename = (
Expand All @@ -149,7 +178,7 @@ def main(args=None):
return 4

# Configure the preprocessor to use the asm-preprocessor-lexer
zxbpp.setMode("asm")
zxbpp.setMode(PreprocMode.ASM)

# Now filter them against the preprocessor
zxbpp.main([OPTIONS.input_filename])
Expand Down
18 changes: 12 additions & 6 deletions src/zxbpp/zxbpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
from enum import Enum, unique
from typing import Any, Final, NamedTuple

from src import arch
from src.api import config, global_, utils
from src.arch import AVAILABLE_ARCHITECTURES
from src.ply import yacc
from src.zxbpp import zxbasmpplex, zxbpplex
from src.zxbpp.base_pplex import STDIN
Expand All @@ -35,6 +33,9 @@ class PreprocMode(str, Enum):
ASM = "ASM"


# List of available architectures
AVAILABLE_ARCHITECTURES: Final[list[str]] = []

# Generated output
OUTPUT = ""

Expand Down Expand Up @@ -124,6 +125,11 @@ def init():
global ENABLED
global IFDEFS

from src import arch

AVAILABLE_ARCHITECTURES.clear()
AVAILABLE_ARCHITECTURES.extend(arch.AVAILABLE_ARCHITECTURES)

config.OPTIONS(config.Action.ADD_IF_NOT_DEFINED, name="debug_zxbpp", type=bool, default=False)
global_.FILENAME = STDIN
OUTPUT = ""
Expand Down Expand Up @@ -1014,9 +1020,9 @@ def entry_point(args=None):
parser.add_argument(
"--arch",
type=str,
default=arch.AVAILABLE_ARCHITECTURES[0],
help=f"Target architecture (defaults is'{arch.AVAILABLE_ARCHITECTURES[0]}'). "
f"Available architectures: {','.join(arch.AVAILABLE_ARCHITECTURES)}",
default=AVAILABLE_ARCHITECTURES[0],
help=f"Target architecture (defaults is'{AVAILABLE_ARCHITECTURES[0]}'). "
f"Available architectures: {','.join(AVAILABLE_ARCHITECTURES)}",
)
parser.add_argument(
"--expect-warnings",
Expand All @@ -1030,7 +1036,7 @@ def entry_point(args=None):
config.OPTIONS.debug_zxbpp = config.OPTIONS.debug_level > 0
config.OPTIONS.expected_warnings = options.expect_warnings

if options.arch not in arch.AVAILABLE_ARCHITECTURES:
if options.arch not in AVAILABLE_ARCHITECTURES:
parser.error(f"Invalid architecture '{options.arch}'") # Exits with error

config.OPTIONS.architecture = options.arch
Expand Down