write labels

This commit is contained in:
Mark Canlas 2020-08-16 01:56:17 -04:00
parent 45af484839
commit 8b839841c1
3 changed files with 17 additions and 21 deletions

View File

@ -5,9 +5,20 @@ import cats.data.NonEmptyList
sealed trait Color
object Color {
implicit val ev: Operand[Color] =
Operand.operandInt
.contra(toByte, _.toString)
implicit val colorOperand: Operand[Color] =
new Operand[Color] {
def toAddressLiteral(x: Color): String =
"#" + x.toString.toLowerCase()
def toShow(x: Color): String =
x.toString
def operandType: OperandType =
ValueLiteral
def toDefinitionLiteral(x: Color): String =
toByte(x).toString
}
implicit val colorEnum: EnumAsm[Color] =
new EnumAsm[Color] {

View File

@ -10,21 +10,6 @@ trait Operand[A] {
def operandType: OperandType
def toDefinitionLiteral(x: A): String
def contra[B](f: B => A, show: B => String): Operand[B] =
new Operand[B] {
val operandType: OperandType =
self.operandType
def toShow(x: B): String =
show(x)
def toDefinitionLiteral(x: B): String =
toAddressLiteral(x)
def toAddressLiteral(x: B): String =
self.toAddressLiteral(f(x))
}
}
object Operand {

View File

@ -18,11 +18,11 @@ class Easy6502Spec extends AnyFlatSpec with should.Matchers {
}
doc.triplets shouldEqual List(
("LDA", "#$01".some, "write White to screen (0)".some),
("LDA", "#white".some, "write White to screen (0)".some),
("STA", "$0200".some, "".some),
("LDA", "#$05".some, "write Green to screen (1)".some),
("LDA", "#green".some, "write Green to screen (1)".some),
("STA", "$0201".some, "".some),
("LDA", "#$08".some, "write Orange to screen (2)".some),
("LDA", "#orange".some, "write Orange to screen (2)".some),
("STA", "$0202".some, "".some)
)