add more devices

This commit is contained in:
Mark Canlas 2020-08-26 00:56:55 -04:00
parent 4859ae575a
commit 58f15e85e8
3 changed files with 15 additions and 5 deletions

View File

@ -2,14 +2,17 @@ package com.htmlism.mos6502.dsl
//import com.htmlism.mos6502.model._
case class ReadWriteDevice[A](address: Address) {
/**
* @tparam A The input type of the write and the output type of the read
*/
case class ReadWriteLocation[A](address: Address) {
def read(implicit ctx: AssemblyContext): Unit = {
val _ = ctx
// ctx.push(LDA, ev, s"write ${ev.toShow(x)} to $name ($n)")
}
def write(implicit ctx: AssemblyContext): Unit = {
val _ = ctx
def write(x: A)(implicit ctx: AssemblyContext): Unit = {
val _ = (x, ctx)
// ctx.push(STA, ev, s"write ${ev.toShow(x)} to $name ($n)")
}
}

View File

@ -2,6 +2,9 @@ package com.htmlism.mos6502.dsl
//import com.htmlism.mos6502.model._
/**
* @tparam A The return type of the read
*/
case class VolatileDevice[A](address: Address) {
def read(implicit ctx: AssemblyContext): Unit = {
val _ = ctx

View File

@ -68,8 +68,10 @@ class Easy6502Spec extends AnyFlatSpec with should.Matchers {
}
"snake" should "compile" in {
val sysRandom = VolatileDevice[Int](0xfe.addr)
val sysLastKey = VolatileDevice[AsciiValue](0xff.addr)
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 initSnake =
sub("initSnake") { implicit a =>
@ -135,6 +137,8 @@ class Easy6502Spec extends AnyFlatSpec with should.Matchers {
asm { implicit a =>
sysRandom.read
sysLastKey.read
snakeDirection.read
appleLocation.read
jump(init)
jump(loop)