mirror of
https://github.com/mcanlas/6502-opcodes.git
synced 2025-02-25 16:28:59 +00:00
add definition literal support
This commit is contained in:
parent
9b60d46e03
commit
45af484839
@ -11,6 +11,9 @@ object ZeroAddress {
|
||||
def toShow(x: ZeroAddress): String =
|
||||
String.format("global address 0x%02x", x.n)
|
||||
|
||||
def toDefinitionLiteral(x: ZeroAddress): String =
|
||||
toAddressLiteral(x)
|
||||
|
||||
def toAddressLiteral(x: ZeroAddress): String =
|
||||
String.format("$%02x", x.n)
|
||||
}
|
||||
@ -27,6 +30,9 @@ object GlobalAddress {
|
||||
def toShow(x: GlobalAddress): String =
|
||||
String.format("global address 0x%04x", x.n)
|
||||
|
||||
def toDefinitionLiteral(x: GlobalAddress): String =
|
||||
toAddressLiteral(x)
|
||||
|
||||
def toAddressLiteral(x: GlobalAddress): String =
|
||||
String.format("$%04x", x.n)
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ class DefinitionGroupContext {
|
||||
case class Definition[A: Operand](name: String, x: A) {
|
||||
lazy val value: String =
|
||||
implicitly[Operand[A]]
|
||||
.toAddressLiteral(x)
|
||||
.toDefinitionLiteral(x)
|
||||
}
|
||||
|
||||
class AsmBlockContext {
|
||||
|
@ -9,6 +9,8 @@ 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 =
|
||||
@ -17,6 +19,9 @@ trait Operand[A] {
|
||||
def toShow(x: B): String =
|
||||
show(x)
|
||||
|
||||
def toDefinitionLiteral(x: B): String =
|
||||
toAddressLiteral(x)
|
||||
|
||||
def toAddressLiteral(x: B): String =
|
||||
self.toAddressLiteral(f(x))
|
||||
}
|
||||
@ -31,6 +36,9 @@ object Operand {
|
||||
def toShow(x: Int): String =
|
||||
x.toString
|
||||
|
||||
def toDefinitionLiteral(x: Int): String =
|
||||
x.toString
|
||||
|
||||
def toAddressLiteral(x: Int): String =
|
||||
String.format("#$%02x", x)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user