operand kinda

This commit is contained in:
Mark Canlas
2020-08-26 04:03:24 -04:00
parent 3f5f6e309d
commit d42ed22153
2 changed files with 16 additions and 4 deletions

View File

@@ -25,4 +25,16 @@ object Operand {
def toAddressLiteral(x: Int): String = def toAddressLiteral(x: Int): String =
String.format("#$%02x", x) String.format("#$%02x", x)
} }
implicit def operandForMapping[A](implicit ev: Mapping[A]): Operand[A] =
new Operand[A] {
def toAddressLiteral(x: A): String =
"#" + ev.label(x)
def toShow(x: A): String =
ev.label(x)
def operandType: OperandType =
ValueLiteral
}
} }

View File

@@ -1,21 +1,21 @@
package com.htmlism.mos6502.dsl package com.htmlism.mos6502.dsl
//import com.htmlism.mos6502.model._ import com.htmlism.mos6502.model._
/** /**
* @param name A name for this location, used to alias its address * @param name A name for this location, used to alias its address
* *
* @tparam A The input type of the write and the output type of the read * @tparam A The input type of the write and the output type of the read
*/ */
case class ReadWriteLocation[A](name: String, address: ZeroAddress) { case class ReadWriteLocation[A: Operand](name: String, address: ZeroAddress) {
def read(implicit ctx: AssemblyContext): Unit = { def read(implicit ctx: AssemblyContext): Unit = {
val _ = ctx val _ = ctx
// ctx.push(LDA, ev, s"write ${ev.toShow(x)} to $name ($n)") // ctx.push(LDA, ev, s"write ${ev.toShow(x)} to $name ($n)")
} }
def write(x: A)(implicit ctx: AssemblyContext): Unit = { def write(x: A)(implicit ctx: AssemblyContext): Unit = {
val _ = (x, ctx) ctx.push(LDA, x)
// ctx.push(STA, ev, s"write ${ev.toShow(x)} to $name ($n)") ctx.push(STA, address) // should be named address
} }
} }