From d42ed2215305178a740106a34dda742e49aa1dea Mon Sep 17 00:00:00 2001 From: Mark Canlas Date: Wed, 26 Aug 2020 04:03:24 -0400 Subject: [PATCH] operand kinda --- src/main/scala/com/htmlism/mos6502/dsl/Operand.scala | 12 ++++++++++++ .../com/htmlism/mos6502/dsl/ReadWriteLocation.scala | 8 ++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/scala/com/htmlism/mos6502/dsl/Operand.scala b/src/main/scala/com/htmlism/mos6502/dsl/Operand.scala index 1cf48d1..9ea0ada 100644 --- a/src/main/scala/com/htmlism/mos6502/dsl/Operand.scala +++ b/src/main/scala/com/htmlism/mos6502/dsl/Operand.scala @@ -25,4 +25,16 @@ object Operand { def toAddressLiteral(x: Int): String = 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 + } } diff --git a/src/main/scala/com/htmlism/mos6502/dsl/ReadWriteLocation.scala b/src/main/scala/com/htmlism/mos6502/dsl/ReadWriteLocation.scala index caa08e8..3bb5bfa 100644 --- a/src/main/scala/com/htmlism/mos6502/dsl/ReadWriteLocation.scala +++ b/src/main/scala/com/htmlism/mos6502/dsl/ReadWriteLocation.scala @@ -1,21 +1,21 @@ 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 * * @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 = { val _ = ctx // ctx.push(LDA, ev, s"write ${ev.toShow(x)} to $name ($n)") } def write(x: A)(implicit ctx: AssemblyContext): Unit = { - val _ = (x, ctx) - // ctx.push(STA, ev, s"write ${ev.toShow(x)} to $name ($n)") + ctx.push(LDA, x) + ctx.push(STA, address) // should be named address } }