diff --git a/src/main/scala/com/htmlism/mos6502/dsl/DslDemo.scala b/src/main/scala/com/htmlism/mos6502/dsl/DslDemo.scala
index 6014c89..5edcc12 100644
--- a/src/main/scala/com/htmlism/mos6502/dsl/DslDemo.scala
+++ b/src/main/scala/com/htmlism/mos6502/dsl/DslDemo.scala
@@ -100,7 +100,7 @@ class CPU {
registers.A
def A_=[A](x: A)(implicit ctx: AssemblyContext, ev: Operand[A]): Unit =
- ctx.push(LDA, x, "set A to value " + ev.toAddressLiteral(x))
+ ctx.push(LDA, x, "set A to " + ev.toShow(x))
def A_=(reg: registers.DestinationA)(implicit ctx: AssemblyContext): Unit =
reg match {
diff --git a/src/main/scala/com/htmlism/mos6502/dsl/GlobalAddress.scala b/src/main/scala/com/htmlism/mos6502/dsl/GlobalAddress.scala
index 31c2586..956c67d 100644
--- a/src/main/scala/com/htmlism/mos6502/dsl/GlobalAddress.scala
+++ b/src/main/scala/com/htmlism/mos6502/dsl/GlobalAddress.scala
@@ -8,6 +8,9 @@ object GlobalAddress {
val operandType: OperandType =
MemoryLocation
+ def toShow(x: GlobalAddress): String =
+ String.format("global address 0x%04x", x.n)
+
def toAddressLiteral(x: GlobalAddress): String =
String.format("$%04x", x.n)
}
@@ -15,7 +18,7 @@ object GlobalAddress {
case class GlobalAddress(n: Int) {
def write[A](x: A)(implicit ctx: AssemblyContext, ev: Operand[A]): Unit = {
- ctx.push(LDA, x, s"write value ${ev.toAddressLiteral(x)} to address $n")
+ ctx.push(LDA, x, s"write ${ev.toShow(x)} to address $n")
ctx.push(STA, this, "")
}
}
diff --git a/src/main/scala/com/htmlism/mos6502/dsl/Operand.scala b/src/main/scala/com/htmlism/mos6502/dsl/Operand.scala
index 96da5fb..a505057 100644
--- a/src/main/scala/com/htmlism/mos6502/dsl/Operand.scala
+++ b/src/main/scala/com/htmlism/mos6502/dsl/Operand.scala
@@ -5,6 +5,8 @@ import cats.Contravariant
trait Operand[A] {
def toAddressLiteral(x: A): String
+ def toShow(x: A): String
+
def operandType: OperandType
}
@@ -14,6 +16,9 @@ object Operand {
val operandType: OperandType =
ValueLiteral
+ def toShow(x: Int): String =
+ x.toString
+
def toAddressLiteral(x: Int): String =
String.format("#$%02x", x)
}
@@ -25,10 +30,11 @@ object Operand {
val operandType: OperandType =
fa.operandType
+ def toShow(x: B): String =
+ fa.toShow(f(x))
+
def toAddressLiteral(x: B): String =
- fa.toAddressLiteral {
- f(x)
- }
+ fa.toAddressLiteral(f(x))
}
}
}
diff --git a/src/main/scala/com/htmlism/mos6502/dsl/ZeroAddress.scala b/src/main/scala/com/htmlism/mos6502/dsl/ZeroAddress.scala
index c93b751..8e1da41 100644
--- a/src/main/scala/com/htmlism/mos6502/dsl/ZeroAddress.scala
+++ b/src/main/scala/com/htmlism/mos6502/dsl/ZeroAddress.scala
@@ -6,6 +6,9 @@ object ZeroAddress {
val operandType: OperandType =
MemoryLocation
+ def toShow(x: ZeroAddress): String =
+ String.format("global address 0x%02x", x.n)
+
def toAddressLiteral(x: ZeroAddress): String =
String.format("$%02x", x.n)
}