mirror of
https://github.com/mcanlas/6502-opcodes.git
synced 2025-01-02 02:31:38 +00:00
thread opts more specifically
This commit is contained in:
parent
def9668d82
commit
1bf474d6bb
@ -40,7 +40,7 @@ object AsmBlock:
|
|||||||
|
|
||||||
"$" + hex.toUpperCase
|
"$" + hex.toUpperCase
|
||||||
|
|
||||||
def toLines(xs: AsmBlock): List[String] =
|
def toLines(opts: AssemblerOptions.InstructionCase)(xs: AsmBlock): List[String] =
|
||||||
xs match
|
xs match
|
||||||
case CommentBlock(ys) =>
|
case CommentBlock(ys) =>
|
||||||
ys.map(toComment)
|
ys.map(toComment)
|
||||||
@ -61,12 +61,12 @@ object AsmBlock:
|
|||||||
List(label + ":") ++ oComment.map(toComment).map(withIndent).toList
|
List(label + ":") ++ oComment.map(toComment).map(withIndent).toList
|
||||||
|
|
||||||
val intentParagraphs =
|
val intentParagraphs =
|
||||||
intents.map(Intent.toLines)
|
intents.map(Intent.toLines(opts))
|
||||||
|
|
||||||
interFlatMap(headerParagraph :: intentParagraphs)(List(""), identity)
|
interFlatMap(headerParagraph :: intentParagraphs)(List(""), identity)
|
||||||
|
|
||||||
case AnonymousCodeBlock(intents) =>
|
case AnonymousCodeBlock(intents) =>
|
||||||
interFlatMap(intents)(List(""), Intent.toLines)
|
interFlatMap(intents)(List(""), Intent.toLines(opts))
|
||||||
|
|
||||||
case class Intent(label: Option[String], instructions: List[Intent.Instruction])
|
case class Intent(label: Option[String], instructions: List[Intent.Instruction])
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ object AsmBlock:
|
|||||||
def length: Int =
|
def length: Int =
|
||||||
0
|
0
|
||||||
|
|
||||||
def toLines(x: Intent): List[String] =
|
def toLines(opts: AssemblerOptions.InstructionCase)(x: Intent): List[String] =
|
||||||
val comment =
|
val comment =
|
||||||
x.label.map(toComment).map(withIndent).toList
|
x.label.map(toComment).map(withIndent).toList
|
||||||
|
|
||||||
@ -97,16 +97,19 @@ object AsmBlock:
|
|||||||
.instructions
|
.instructions
|
||||||
.map {
|
.map {
|
||||||
case Instruction.Zero(code, oComment) =>
|
case Instruction.Zero(code, oComment) =>
|
||||||
|
val codeUpperLower =
|
||||||
|
instruction(code, opts)
|
||||||
|
|
||||||
oComment match
|
oComment match
|
||||||
case Some(c) =>
|
case Some(c) =>
|
||||||
String.format(s"%-${maximumLength}s", code) + " " + toComment(c)
|
String.format(s"%-${maximumLength}s", codeUpperLower) + " " + toComment(c)
|
||||||
|
|
||||||
case None =>
|
case None =>
|
||||||
code
|
codeUpperLower
|
||||||
|
|
||||||
case Instruction.One(code, operand, oComment) =>
|
case Instruction.One(code, operand, oComment) =>
|
||||||
val leftSlug =
|
val leftSlug =
|
||||||
code + " " + operand
|
instruction(code, opts) + " " + operand
|
||||||
|
|
||||||
oComment match
|
oComment match
|
||||||
case Some(c) =>
|
case Some(c) =>
|
||||||
@ -118,3 +121,11 @@ object AsmBlock:
|
|||||||
.map(withIndent)
|
.map(withIndent)
|
||||||
|
|
||||||
comment ++ instructions
|
comment ++ instructions
|
||||||
|
|
||||||
|
def instruction(s: String, instructionCase: AssemblerOptions.InstructionCase): String =
|
||||||
|
instructionCase match
|
||||||
|
case AssemblerOptions.InstructionCase.Uppercase =>
|
||||||
|
s.toUpperCase
|
||||||
|
|
||||||
|
case AssemblerOptions.InstructionCase.Lowercase =>
|
||||||
|
s.toLowerCase
|
||||||
|
@ -51,7 +51,7 @@ object AnnotatedSnake:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.map(AsmBlock.toLines)
|
.map(AsmBlock.toLines(AssemblerOptions.InstructionCase.Lowercase))
|
||||||
.pipe(xs => AsmBlock.interFlatMap(xs)(List("", ""), identity))
|
.pipe(xs => AsmBlock.interFlatMap(xs)(List("", ""), identity))
|
||||||
.pipe(str.Line.mkString)
|
.pipe(str.Line.mkString)
|
||||||
|
|
||||||
|
@ -29,13 +29,13 @@ object PrintThree:
|
|||||||
build(Easy6502.Screen(0x200))
|
build(Easy6502.Screen(0x200))
|
||||||
|
|
||||||
def assemble(opts: AssemblerOptions): String =
|
def assemble(opts: AssemblerOptions): String =
|
||||||
(defines(opts) ++ codes(opts))
|
(defines(opts.definitionsMode) ++ codes(opts.definitionsMode))
|
||||||
.map(AsmBlock.toLines)
|
.map(AsmBlock.toLines(opts.instructionCase))
|
||||||
.pipe(xs => AsmBlock.interFlatMap(xs)(List("", ""), identity))
|
.pipe(xs => AsmBlock.interFlatMap(xs)(List("", ""), identity))
|
||||||
.pipe(str.Line.mkString)
|
.pipe(str.Line.mkString)
|
||||||
|
|
||||||
private def defines(opts: AssemblerOptions) =
|
private def defines(opts: AssemblerOptions.DefinitionsMode) =
|
||||||
opts.definitionsMode match
|
opts match
|
||||||
case AssemblerOptions.DefinitionsMode.UseLiterals =>
|
case AssemblerOptions.DefinitionsMode.UseLiterals =>
|
||||||
Nil
|
Nil
|
||||||
|
|
||||||
@ -49,11 +49,11 @@ object PrintThree:
|
|||||||
.pipe(AsmBlock.DefinesBlock(_))
|
.pipe(AsmBlock.DefinesBlock(_))
|
||||||
}
|
}
|
||||||
|
|
||||||
private def codes(opts: AssemblerOptions) =
|
private def codes(opts: AssemblerOptions.DefinitionsMode) =
|
||||||
program
|
program
|
||||||
.map { mv =>
|
.map { mv =>
|
||||||
val argument =
|
val argument =
|
||||||
opts.definitionsMode match
|
opts match
|
||||||
case AssemblerOptions.DefinitionsMode.UseLiterals =>
|
case AssemblerOptions.DefinitionsMode.UseLiterals =>
|
||||||
f"#$$${mv.src.toValue}%02X"
|
f"#$$${mv.src.toValue}%02X"
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ object PrintThree:
|
|||||||
"#" + mv.src.toDefine
|
"#" + mv.src.toDefine
|
||||||
|
|
||||||
val argumentTwo =
|
val argumentTwo =
|
||||||
opts.definitionsMode match
|
opts match
|
||||||
case AssemblerOptions.DefinitionsMode.UseLiterals =>
|
case AssemblerOptions.DefinitionsMode.UseLiterals =>
|
||||||
AsmBlock.toHex(mv.dest.toValue)
|
AsmBlock.toHex(mv.dest.toValue)
|
||||||
|
|
||||||
@ -78,12 +78,12 @@ object PrintThree:
|
|||||||
AsmBlock
|
AsmBlock
|
||||||
.Intent
|
.Intent
|
||||||
.Instruction
|
.Instruction
|
||||||
.One(instruction("LDA", opts.instructionCase), argument, s"a = ${mv.src.toComment}".some),
|
.One("LDA", argument, s"a = ${mv.src.toComment}".some),
|
||||||
AsmBlock
|
AsmBlock
|
||||||
.Intent
|
.Intent
|
||||||
.Instruction
|
.Instruction
|
||||||
.One(
|
.One(
|
||||||
instruction("STA", opts.instructionCase),
|
"STA",
|
||||||
argumentTwo,
|
argumentTwo,
|
||||||
s"${mv.dest.toComment} = a".some
|
s"${mv.dest.toComment} = a".some
|
||||||
)
|
)
|
||||||
@ -92,11 +92,3 @@ object PrintThree:
|
|||||||
}
|
}
|
||||||
.pipe(AnonymousCodeBlock(_))
|
.pipe(AnonymousCodeBlock(_))
|
||||||
.pipe(List(_))
|
.pipe(List(_))
|
||||||
|
|
||||||
def instruction(s: String, instructionCase: AssemblerOptions.InstructionCase): String =
|
|
||||||
instructionCase match
|
|
||||||
case AssemblerOptions.InstructionCase.Uppercase =>
|
|
||||||
s.toUpperCase
|
|
||||||
|
|
||||||
case AssemblerOptions.InstructionCase.Lowercase =>
|
|
||||||
s.toLowerCase
|
|
||||||
|
Loading…
Reference in New Issue
Block a user