diff --git a/docs/api/custom-platform.md b/docs/api/custom-platform.md index f6acd68c..16aea468 100644 --- a/docs/api/custom-platform.md +++ b/docs/api/custom-platform.md @@ -217,11 +217,15 @@ Default: `main,*` * `length+123`, `length_be+123` – the same, but incremented by the given number * `length-123`, `length_be-123` – the same, but decremented by the given number + + * `programname-123` – the name of the program of the given length, uppercase ASCII, padded with spaces * `allocated` – all used bytes * `pagecount` – the number of pages used by all used bytes (including partially filled pages) + * `""` – literal ASCII string; commas, non-ASCII characters and escape sequences are not supported + * `:` - inclusive range of bytes * `::` - inclusive range of bytes in a given segment diff --git a/src/main/scala/millfork/Platform.scala b/src/main/scala/millfork/Platform.scala index d2e819bd..48019461 100644 --- a/src/main/scala/millfork/Platform.scala +++ b/src/main/scala/millfork/Platform.scala @@ -265,6 +265,8 @@ object Platform { case "startpage" => StartPageOutput case "endaddr" => EndAddressOutput(0) case "endaddr_be" => EndAddressOutputBe(0) + case l if l.startsWith("\"") && l.endsWith("\"") => StringOutput(l.substring(1, l.length - 1)) + case l if l.startsWith("programname-") => ProgramNameOutput(parseNumber(l.stripPrefix("programname-"))) case l if l.startsWith("startaddr+") => StartAddressOutput(parseNumber(l.stripPrefix("startaddr+"))) case l if l.startsWith("startaddr-") => StartAddressOutput(-parseNumber(l.stripPrefix("startaddr-"))) case l if l.startsWith("startaddr_be+") => StartAddressOutputBe(parseNumber(l.stripPrefix("startaddr_be+"))) diff --git a/src/main/scala/millfork/output/OutputPackager.scala b/src/main/scala/millfork/output/OutputPackager.scala index ee4e5a06..2f0d6261 100644 --- a/src/main/scala/millfork/output/OutputPackager.scala +++ b/src/main/scala/millfork/output/OutputPackager.scala @@ -1,6 +1,8 @@ package millfork.output import java.io.ByteArrayOutputStream +import java.nio.charset.StandardCharsets +import java.util.Locale /** * @author Karol Stasiak @@ -38,6 +40,19 @@ case class BankFragmentOutput(alwaysBank: String, start: Int, end: Int) extends } } +case class ProgramNameOutput(length: Int) extends OutputPackager { + def isAlphanum(c: Char): Boolean = (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') + def packageOutput(mem: CompiledMemory, bank: String): Array[Byte] = { + mem.programName.toUpperCase(Locale.ROOT).filter(isAlphanum).take(length).padTo(length, ' ').getBytes(StandardCharsets.US_ASCII) + } +} + +case class StringOutput(string: String) extends OutputPackager { + def packageOutput(mem: CompiledMemory, bank: String): Array[Byte] = { + string.getBytes(StandardCharsets.US_ASCII) + } +} + case class StartAddressOutput(bonus: Int) extends OutputPackager { def packageOutput(mem: CompiledMemory, bank: String): Array[Byte] = { val b = mem.banks(bank)