mirror of
https://github.com/mcanlas/6502-opcodes.git
synced 2025-01-02 17:30:44 +00:00
specify byte width
This commit is contained in:
parent
3c1d811aef
commit
65065e074e
@ -1,7 +1,7 @@
|
||||
package com.htmlism.nescant
|
||||
|
||||
trait Sink[A]
|
||||
trait ByteSink[A]
|
||||
|
||||
object Sink {
|
||||
object ByteSink {
|
||||
// TODO int cannot be a source
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.htmlism.nescant
|
||||
|
||||
trait ByteSource[A]
|
||||
|
||||
object ByteSource {
|
||||
implicit val sourceForInt: ByteSource[Int] =
|
||||
new ByteSource[Int] {}
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
package com.htmlism.nescant
|
||||
|
||||
object GlobalAddress {
|
||||
implicit val sourceForGlobalAddress: Source[GlobalAddress] =
|
||||
new Source[GlobalAddress] {}
|
||||
implicit val sourceForGlobalAddress: ByteSource[GlobalAddress] =
|
||||
new ByteSource[GlobalAddress] {}
|
||||
|
||||
implicit val sinkForGlobalAddress: Sink[GlobalAddress] =
|
||||
new Sink[GlobalAddress] {}
|
||||
implicit val sinkForGlobalAddress: ByteSink[GlobalAddress] =
|
||||
new ByteSink[GlobalAddress] {}
|
||||
}
|
||||
|
||||
case class GlobalAddress(n: Int)
|
||||
|
@ -8,11 +8,11 @@ package com.htmlism.nescant
|
||||
case class ReadWriteLocation[A](name: String, address: ZeroPageAddress)
|
||||
|
||||
object ReadWriteLocation {
|
||||
implicit def sourceForReadWriteLocation[A: Operand]: Source[ReadWriteLocation[A]] =
|
||||
new Source[ReadWriteLocation[A]] {}
|
||||
implicit def sourceForReadWriteLocation[A: Operand]: ByteSource[ReadWriteLocation[A]] =
|
||||
new ByteSource[ReadWriteLocation[A]] {}
|
||||
|
||||
implicit def sinkForReadWriteLocation[A: Operand]: Sink[ReadWriteLocation[A]] =
|
||||
new Sink[ReadWriteLocation[A]] {}
|
||||
implicit def sinkForReadWriteLocation[A: Operand]: ByteSink[ReadWriteLocation[A]] =
|
||||
new ByteSink[ReadWriteLocation[A]] {}
|
||||
|
||||
implicit def operandForReadWriteLocation[A: Operand]: Operand[ReadWriteLocation[A]] =
|
||||
new Operand[ReadWriteLocation[A]] {
|
||||
|
@ -1,8 +0,0 @@
|
||||
package com.htmlism.nescant
|
||||
|
||||
trait Source[A]
|
||||
|
||||
object Source {
|
||||
implicit val sourceForInt: Source[Int] =
|
||||
new Source[Int] {}
|
||||
}
|
@ -12,8 +12,8 @@ package com.htmlism.nescant
|
||||
case class VolatileDevice[A](name: String, address: ZeroPageAddress)
|
||||
|
||||
object VolatileDevice {
|
||||
implicit def sourceForVolatileDevice[A: Operand]: Source[VolatileDevice[A]] =
|
||||
new Source[VolatileDevice[A]] {}
|
||||
implicit def sourceForVolatileDevice[A: Operand]: ByteSource[VolatileDevice[A]] =
|
||||
new ByteSource[VolatileDevice[A]] {}
|
||||
|
||||
implicit def operandForVolatileDevice[A: Operand]: Operand[VolatileDevice[A]] =
|
||||
new Operand[VolatileDevice[A]] {
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.htmlism.nescant
|
||||
|
||||
object ZeroPageAddress {
|
||||
implicit val sourceForZeroPageAddress: Source[ZeroPageAddress] =
|
||||
new Source[ZeroPageAddress] {}
|
||||
implicit val sourceForZeroPageAddress: ByteSource[ZeroPageAddress] =
|
||||
new ByteSource[ZeroPageAddress] {}
|
||||
|
||||
implicit val sinkForZeroPageAddress: Sink[ZeroPageAddress] =
|
||||
new Sink[ZeroPageAddress] {}
|
||||
implicit val sinkForZeroPageAddress: ByteSink[ZeroPageAddress] =
|
||||
new ByteSink[ZeroPageAddress] {}
|
||||
}
|
||||
|
||||
case class ZeroPageAddress(n: Int)
|
||||
|
@ -9,8 +9,8 @@ package object dsl {
|
||||
GlobalAddress(n)
|
||||
}
|
||||
|
||||
implicit class SinkOps[A: Sink](x: A) {
|
||||
def write[B: Source](src: B): Unit = {
|
||||
implicit class SinkOps[A: ByteSink](x: A) {
|
||||
def write[B: ByteSource](src: B): Unit = {
|
||||
val _ = src
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
package com.htmlism.nescant
|
||||
package dsl
|
||||
|
||||
import org.scalatest.flatspec._
|
||||
import org.scalatest.matchers._
|
||||
|
||||
class ByteSinkSpec extends AnyFlatSpec with should.Matchers {
|
||||
"A zero page address" should "be a byte-wide sync" in {
|
||||
123.z.write(456)
|
||||
}
|
||||
|
||||
"A global address" should "be a byte-wide sync" in {
|
||||
123.g.write(456)
|
||||
}
|
||||
|
||||
"A read write location" should "be a byte-wide sync" in {
|
||||
val sink = ReadWriteLocation[Int]("", 0.z)
|
||||
|
||||
sink.write(456)
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.htmlism.nescant
|
||||
package dsl
|
||||
|
||||
import org.scalatest.flatspec._
|
||||
import org.scalatest.matchers._
|
||||
|
||||
class ByteSourceSpec extends AnyFlatSpec with should.Matchers {
|
||||
private val sink =
|
||||
123.z
|
||||
|
||||
"A number" should "be a byte-wide source" in {
|
||||
sink.write(456)
|
||||
}
|
||||
|
||||
"A zero page address" should "be a byte-wide source" in {
|
||||
sink.write(456.z)
|
||||
}
|
||||
|
||||
"A global address" should "be a byte-wide source" in {
|
||||
sink.write(456.g)
|
||||
}
|
||||
|
||||
"A volatile device" should "be a byte-wide source" in {
|
||||
val src = VolatileDevice[Int]("", 0.z)
|
||||
|
||||
sink.write(src)
|
||||
}
|
||||
|
||||
"A read write location" should "be a byte-wide source" in {
|
||||
val src = ReadWriteLocation[Int]("", 0.z)
|
||||
|
||||
sink.write(src)
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package com.htmlism.nescant
|
||||
package dsl
|
||||
|
||||
import org.scalatest.flatspec._
|
||||
import org.scalatest.matchers._
|
||||
|
||||
class SinkSpec extends AnyFlatSpec with should.Matchers {
|
||||
"A zero page address" should "be a sink" in {
|
||||
123.z.write(456)
|
||||
}
|
||||
|
||||
"A global address" should "be a sink" in {
|
||||
123.g.write(456)
|
||||
}
|
||||
|
||||
"A read write location" should "be a sink" in {
|
||||
val sink = ReadWriteLocation[Int]("", 0.z)
|
||||
|
||||
sink.write(456)
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package com.htmlism.nescant
|
||||
package dsl
|
||||
|
||||
import org.scalatest.flatspec._
|
||||
import org.scalatest.matchers._
|
||||
|
||||
class SourceSpec extends AnyFlatSpec with should.Matchers {
|
||||
"A number" should "be a source" in {
|
||||
123.z.write(456)
|
||||
}
|
||||
|
||||
"A zero page address" should "be a source" in {
|
||||
123.z.write(456.z)
|
||||
}
|
||||
|
||||
"A global address" should "be a source" in {
|
||||
123.z.write(456.g)
|
||||
}
|
||||
|
||||
"A volatile device" should "be a source" in {
|
||||
val src = VolatileDevice[Int]("", 0.z)
|
||||
|
||||
123.z.write(src)
|
||||
}
|
||||
|
||||
"A read write location" should "be a source" in {
|
||||
val src = ReadWriteLocation[Int]("", 0.z)
|
||||
|
||||
123.z.write(src)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user