add snake length; more documentation

This commit is contained in:
Mark Canlas 2020-08-26 01:28:36 -04:00
parent 8b9828c63e
commit 0902288b15
3 changed files with 13 additions and 6 deletions

View File

@ -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)")

View File

@ -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)")

View File

@ -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 =>