1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-12-22 16:31:02 +00:00

New output elements: literal ASCII strings and space-padded program name

This commit is contained in:
Karol Stasiak 2020-09-29 22:47:05 +02:00
parent 2d7c365b20
commit c7008f4414
3 changed files with 21 additions and 0 deletions

View File

@ -218,10 +218,14 @@ Default: `main,*`
* `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)
* `"<string>"` literal ASCII string; commas, non-ASCII characters and escape sequences are not supported
* `<addr>:<addr>` - inclusive range of bytes
* `<segment>:<addr>:<addr>` - inclusive range of bytes in a given segment

View File

@ -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+")))

View File

@ -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)