2020-08-14 20:54:29 +00:00
|
|
|
package com.htmlism.mos6502.dsl
|
|
|
|
|
2020-08-15 05:27:13 +00:00
|
|
|
import cats.implicits._
|
2020-08-15 06:04:21 +00:00
|
|
|
|
2020-08-15 04:41:18 +00:00
|
|
|
import com.htmlism.mos6502.model.Instruction
|
2020-08-14 20:54:29 +00:00
|
|
|
|
2020-08-14 21:08:59 +00:00
|
|
|
sealed trait Statement {
|
|
|
|
def toAsm: String
|
2020-08-15 05:27:13 +00:00
|
|
|
|
|
|
|
def toTriplet: (String, Option[String], Option[String])
|
2020-08-14 21:08:59 +00:00
|
|
|
}
|
2020-08-14 20:54:29 +00:00
|
|
|
|
2020-08-14 21:08:59 +00:00
|
|
|
case class UnaryInstruction(instruction: Instruction, comment: Option[String]) extends Statement {
|
|
|
|
def toAsm: String = {
|
|
|
|
val left =
|
|
|
|
instruction.toString
|
2020-08-14 20:54:29 +00:00
|
|
|
|
2020-08-14 21:08:59 +00:00
|
|
|
comment match {
|
|
|
|
case Some(c) =>
|
|
|
|
f"$left%-16s ; " + c
|
|
|
|
case None =>
|
|
|
|
left
|
|
|
|
}
|
|
|
|
}
|
2020-08-15 05:27:13 +00:00
|
|
|
|
|
|
|
def toTriplet: (String, Option[String], Option[String]) =
|
|
|
|
(instruction.toString, None, comment)
|
2020-08-14 21:08:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 07:52:11 +00:00
|
|
|
case class InstructionWithOperand[A](instruction: Instruction, operand: A, comment: Option[String])(implicit
|
|
|
|
ev: Operand[A]
|
2020-08-15 04:49:07 +00:00
|
|
|
) extends Statement {
|
2020-08-14 21:08:59 +00:00
|
|
|
def toAsm: String = {
|
|
|
|
val left =
|
|
|
|
instruction.toString
|
|
|
|
|
|
|
|
val operandStr =
|
2020-08-15 02:02:34 +00:00
|
|
|
ev.toAddressLiteral(operand)
|
2020-08-14 21:08:59 +00:00
|
|
|
|
|
|
|
comment match {
|
|
|
|
case Some(c) =>
|
|
|
|
f"$left%-5s $operandStr%-11s; " + c
|
|
|
|
case None =>
|
|
|
|
f"$left%-5s $operandStr"
|
|
|
|
}
|
|
|
|
}
|
2020-08-15 05:27:13 +00:00
|
|
|
|
|
|
|
def toTriplet: (String, Option[String], Option[String]) =
|
|
|
|
(instruction.toString, ev.toAddressLiteral(operand).some, comment)
|
2020-08-14 21:08:59 +00:00
|
|
|
}
|