2020-08-25 01:15:17 +00:00
|
|
|
package com.htmlism.mos6502.dsl
|
|
|
|
|
2023-10-03 20:15:10 +00:00
|
|
|
import com.htmlism.mos6502.model.*
|
2020-08-25 01:15:17 +00:00
|
|
|
|
2020-08-26 04:56:55 +00:00
|
|
|
/**
|
2021-09-06 08:16:08 +00:00
|
|
|
* @param name
|
|
|
|
* A name for this location, used to alias its address
|
2020-08-26 05:28:36 +00:00
|
|
|
*
|
2021-09-06 08:16:08 +00:00
|
|
|
* @tparam A
|
|
|
|
* The input type of the write and the output type of the read
|
2020-08-26 04:56:55 +00:00
|
|
|
*/
|
2022-02-14 23:11:45 +00:00
|
|
|
case class ReadWriteLocation[A: Operand](name: String, address: ZeroAddress):
|
2023-06-19 09:30:17 +00:00
|
|
|
def read(using ctx: AssemblyContext): Unit =
|
2020-08-25 01:15:17 +00:00
|
|
|
val _ = ctx
|
|
|
|
// ctx.push(LDA, ev, s"write ${ev.toShow(x)} to $name ($n)")
|
|
|
|
|
2023-06-19 09:30:17 +00:00
|
|
|
def write(x: A)(using ctx: AssemblyContext): Unit =
|
2020-08-26 08:03:24 +00:00
|
|
|
ctx.push(LDA, x)
|
2020-08-26 14:26:37 +00:00
|
|
|
ctx.push(STA, this)
|
2020-08-26 06:06:54 +00:00
|
|
|
|
2022-02-14 23:11:45 +00:00
|
|
|
object ReadWriteLocation:
|
2023-06-19 09:33:38 +00:00
|
|
|
given operandForReadWriteLocation[A]: Operand[ReadWriteLocation[A]] =
|
2022-09-07 15:21:22 +00:00
|
|
|
new Operand[ReadWriteLocation[A]]:
|
2020-08-26 14:26:37 +00:00
|
|
|
def toAddressLiteral(x: ReadWriteLocation[A]): String =
|
|
|
|
x.name
|
|
|
|
|
|
|
|
def toShow(x: ReadWriteLocation[A]): String =
|
|
|
|
x.name
|
|
|
|
|
|
|
|
def operandType: OperandType =
|
|
|
|
MemoryLocation
|
|
|
|
|
2023-06-19 09:33:38 +00:00
|
|
|
given namedResourceForReadWriteLocation[A]: NamedResource[ReadWriteLocation[A]] =
|
2022-09-07 15:21:22 +00:00
|
|
|
new NamedResource[ReadWriteLocation[A]]:
|
2020-08-26 06:15:40 +00:00
|
|
|
def toDefinitions(x: ReadWriteLocation[A]): List[Definition[ZeroAddress]] =
|
2023-06-13 17:00:06 +00:00
|
|
|
List:
|
2020-08-26 06:37:12 +00:00
|
|
|
Definition(x.name, x.address, "Read/write location for A values")
|