6502-opcodes/firepower-demo/src/main/scala/com/htmlism/firepower/demo/PrintThree.scala
2022-12-06 13:43:48 -05:00

44 lines
1.2 KiB
Scala

package com.htmlism.firepower.demo
import scala.util.chaining._
import cats.syntax.all._
import com.htmlism.firepower.core.AsmBlock._
import com.htmlism.firepower.core._
object PrintThree:
case class Move(src: String, dest: String)
val program: List[Move] =
List(
Move("#$01", "$0200"),
Move("#$03", "$0201"),
Move("#$05", "$0202")
)
def assemble(opt: AssemblerOptions): String =
program
.map { mv =>
AsmBlock.Intent(
None,
List(
AsmBlock.Intent.Instruction(instruction("LDA", opt.instructionCase) + " " + mv.src, None),
AsmBlock.Intent.Instruction(instruction("STA", opt.instructionCase) + " " + mv.dest, None)
)
)
}
.pipe(AnonymousCodeBlock(_))
.pipe(List(_))
.map(AsmBlock.toLines)
.pipe(xs => AsmBlock.interFlatMap(xs)(List("", ""), identity))
.pipe(str.Line.mkString)
def instruction(s: String, instructionCase: AssemblerOptions.InstructionCase): String =
instructionCase match
case AssemblerOptions.InstructionCase.Uppercase =>
s.toUpperCase
case AssemblerOptions.InstructionCase.Lowercase =>
s.toLowerCase