From bf47473162fa08a8d831f524dc7892bb08c20dc6 Mon Sep 17 00:00:00 2001 From: Karol Stasiak Date: Mon, 6 Aug 2018 19:15:41 +0200 Subject: [PATCH] Allow setting the size of the zeropage register from the command line. --- docs/api/command-line.md | 7 ++++--- src/main/scala/millfork/Main.scala | 17 ++++++++++++----- src/main/scala/millfork/cli/CliOption.scala | 6 ++++++ src/main/scala/millfork/cli/CliParser.scala | 8 ++++---- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/docs/api/command-line.md b/docs/api/command-line.md index f98c9999..4b838aca 100644 --- a/docs/api/command-line.md +++ b/docs/api/command-line.md @@ -81,10 +81,11 @@ Default: native if targeting 65816, no otherwise. `.ini` equivalent: `prevent_jmp_indirect_bug`. Default: no if targeting a 65C02-compatible architecture or a non-6502 architecture, yes otherwise. -* `-fzp-register`, `-fno-zp-register` – Whether should reserve 4 bytes of zero page as a pseudoregister. -Increases language features. +* `-fzp-register=[0-15]`, `-fno-zp-register` – Sets the size of the zeropage pseudoregister. +Increases language features on 6502-based targets. +Recommended values: 2 or 4. Values higher than 4 are pointless. `.ini` equivalent: `zeropage_register`. -Default: yes if targeting a 6502-based architecture, no otherwise. +Default: 4 if targeting a 6502-based architecture, 0 otherwise. * `-fdecimal-mode`, `-fno-decimal-mode` – Whether hardware decimal mode should be used (6502 only). diff --git a/src/main/scala/millfork/Main.scala b/src/main/scala/millfork/Main.scala index 424b9342..50b5e656 100644 --- a/src/main/scala/millfork/Main.scala +++ b/src/main/scala/millfork/Main.scala @@ -323,7 +323,7 @@ object Main { }.description("Whether should emit 65CE02 opcodes.") boolean("-fhuc6280-ops", "-fno-huc6280-ops").action { (c, v) => c.changeFlag(CompilationFlag.EmitHudsonOpcodes, v) - }.description("Whether should emit HuC6280huc6280 opcodes.") + }.description("Whether should emit HuC6280 opcodes.") flag("-fno-65816-ops").action { c => c.changeFlag(CompilationFlag.EmitEmulation65816Opcodes, b = false) c.changeFlag(CompilationFlag.EmitNative65816Opcodes, b = false) @@ -344,12 +344,19 @@ object Main { boolean("-fillegals", "-fno-illegals").action { (c, v) => c.changeFlag(CompilationFlag.EmitIllegals, v) }.description("Whether should emit illegal (undocumented) NMOS opcodes. Requires -O2 or higher to have an effect.") - boolean("-fzp-register", "-fno-zp-register").action { (c, v) => - c.copy(zpRegisterSize = Some(if (v) 2 else 0)) // TODO - }.description("Whether should use 2 bytes of zeropage as a pseudoregister.") + flag("-fzp-register=[0-15]").description("Set the size of the zeropage pseudoregister (6502 only).").dummy() + (0 to 15).foreach(i => + flag("-fzp-register="+i).action(c => c.copy(zpRegisterSize = Some(i))).hidden() + ) + flag("-fzp-register").action { c => + c.copy(zpRegisterSize = Some(4)) + }.description("Alias for -fzp-register=4.") + flag("-fno-zp-register").action { c => + c.copy(zpRegisterSize = Some(0)) + }.description("Alias for -fzp-register=0.") boolean("-fjmp-fix", "-fno-jmp-fix").action { (c, v) => c.changeFlag(CompilationFlag.PreventJmpIndirectBug, v) - }.description("Whether should prevent indirect JMP bug on page boundary.") + }.description("Whether should prevent indirect JMP bug on page boundary (6502 only).") boolean("-fdecimal-mode", "-fno-decimal-mode").action { (c, v) => c.changeFlag(CompilationFlag.DecimalMode, v) }.description("Whether hardware decimal mode should be used (6502 only).") diff --git a/src/main/scala/millfork/cli/CliOption.scala b/src/main/scala/millfork/cli/CliOption.scala index 91925f55..78184140 100644 --- a/src/main/scala/millfork/cli/CliOption.scala +++ b/src/main/scala/millfork/cli/CliOption.scala @@ -25,6 +25,7 @@ trait CliOption[T, O <: CliOption[T, O]] { private[cli] val _shortName: String private[cli] var _description: String = "" private[cli] var _hidden = false + private[cli] var _dummy = false private[cli] var _maxEncounters = 1 private[cli] var _minEncounters = 0 private[cli] var _actualEncounters = 0 @@ -71,6 +72,11 @@ trait CliOption[T, O <: CliOption[T, O]] { this } + def dummy(): O = { + _dummy = true + this + } + def minCount(count: Int): O = { _minEncounters = count this diff --git a/src/main/scala/millfork/cli/CliParser.scala b/src/main/scala/millfork/cli/CliParser.scala index 25c7563f..d45ae7b9 100644 --- a/src/main/scala/millfork/cli/CliParser.scala +++ b/src/main/scala/millfork/cli/CliParser.scala @@ -41,16 +41,16 @@ class CliParser[T] { args match { case k :: v :: xs if mapOptions.contains(k) => mapOptions(k) match { - case p: ParamOption[T] => parseInner(p.encounter(v, context), xs) + case p: ParamOption[T] if !p._dummy => parseInner(p.encounter(v, context), xs) case _ => ??? } case k :: xs if mapFlags.contains(k) => mapFlags(k) match { - case p: FlagOption[T] => + case p: FlagOption[T] if !p._dummy => parseInner(p.encounter(context), xs) - case p: BooleanOption[T] => + case p: BooleanOption[T] if !p._dummy => parseInner(p.encounter(k, context), xs) - case p: NoMoreOptions[T] => + case p: NoMoreOptions[T] if !p._dummy => p.encounter() xs.foldLeft(context)((t, x) => _default.encounter(x, t)) case _ => ???