From 0902288b1548ffbbe2702468232dfa2b6e4a29e5 Mon Sep 17 00:00:00 2001 From: Mark Canlas Date: Wed, 26 Aug 2020 01:28:36 -0400 Subject: [PATCH] add snake length; more documentation --- .../com/htmlism/mos6502/dsl/ReadWriteLocation.scala | 4 +++- .../scala/com/htmlism/mos6502/dsl/VolatileDevice.scala | 6 +++++- .../com/htmlism/mos6502/dsl/snake/Easy6502Spec.scala | 9 +++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/scala/com/htmlism/mos6502/dsl/ReadWriteLocation.scala b/src/main/scala/com/htmlism/mos6502/dsl/ReadWriteLocation.scala index 9661c48..1e5b977 100644 --- a/src/main/scala/com/htmlism/mos6502/dsl/ReadWriteLocation.scala +++ b/src/main/scala/com/htmlism/mos6502/dsl/ReadWriteLocation.scala @@ -3,9 +3,11 @@ package com.htmlism.mos6502.dsl //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](address: Address) { +case class ReadWriteLocation[A](name: String, address: Address) { def read(implicit ctx: AssemblyContext): Unit = { val _ = ctx // ctx.push(LDA, ev, s"write ${ev.toShow(x)} to $name ($n)") diff --git a/src/main/scala/com/htmlism/mos6502/dsl/VolatileDevice.scala b/src/main/scala/com/htmlism/mos6502/dsl/VolatileDevice.scala index b861c6a..82b97fc 100644 --- a/src/main/scala/com/htmlism/mos6502/dsl/VolatileDevice.scala +++ b/src/main/scala/com/htmlism/mos6502/dsl/VolatileDevice.scala @@ -3,9 +3,13 @@ package com.htmlism.mos6502.dsl //import com.htmlism.mos6502.model._ /** + * For a memory-mapped device that may return different values across multiple reads (e.g. a random number generator) + * + * @param name A name for this device, used to alias its address + * * @tparam A The return type of the read */ -case class VolatileDevice[A](address: Address) { +case class VolatileDevice[A](name: String, address: Address) { def read(implicit ctx: AssemblyContext): Unit = { val _ = ctx // ctx.push(LDA, ev, s"write ${ev.toShow(x)} to $name ($n)") diff --git a/src/test/scala/com/htmlism/mos6502/dsl/snake/Easy6502Spec.scala b/src/test/scala/com/htmlism/mos6502/dsl/snake/Easy6502Spec.scala index e0cad44..3d3a522 100644 --- a/src/test/scala/com/htmlism/mos6502/dsl/snake/Easy6502Spec.scala +++ b/src/test/scala/com/htmlism/mos6502/dsl/snake/Easy6502Spec.scala @@ -68,10 +68,11 @@ class Easy6502Spec extends AnyFlatSpec with should.Matchers { } "snake" should "compile" in { - val sysRandom = VolatileDevice[Int](0xfe.z) - val sysLastKey = VolatileDevice[AsciiValue](0xff.z) - val snakeDirection = ReadWriteLocation[Direction](0x02.z) - val appleLocation = ReadWriteLocation[Int](0x00.z) + val sysRandom = VolatileDevice[Int]("sysRandom", 0xfe.z) + val sysLastKey = VolatileDevice[AsciiValue]("sysLastKey", 0xff.z) + val snakeDirection = ReadWriteLocation[Direction]("snakeDirection", 0x02.z) + val appleLocation = ReadWriteLocation[Int]("appleLocation", 0x00.z) + val snakeLength = ReadWriteLocation[Int]("snakeLength", 0x00.z) val initSnake = sub("initSnake") { implicit a =>