mirror of
https://github.com/mcanlas/6502-opcodes.git
synced 2024-06-26 01:29:31 +00:00
output ints
This commit is contained in:
parent
a13a366b2c
commit
6345d6c0fd
|
@ -0,0 +1,3 @@
|
||||||
|
package com.htmlism.scratchpad
|
||||||
|
trait Companion[A]:
|
||||||
|
def canon: A
|
|
@ -1,9 +1,12 @@
|
||||||
package com.htmlism.scratchpad
|
package com.htmlism.scratchpad
|
||||||
|
|
||||||
object Encoded:
|
object Encoded:
|
||||||
trait Byte[A]
|
trait Byte[A]:
|
||||||
|
def int(x: A): Int
|
||||||
|
|
||||||
object Byte:
|
object Byte:
|
||||||
given Encoded.Byte[Int] with {}
|
given Encoded.Byte[Int] with
|
||||||
|
def int(x: Int): Int =
|
||||||
|
x
|
||||||
|
|
||||||
trait Word[A]
|
trait Word[A]
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.htmlism.scratchpad
|
||||||
|
|
||||||
|
trait GrantsWriteLeases[A]:
|
||||||
|
def withWriteLease[B](f: WriteLease[A] => B)(using A: Companion[A]): B =
|
||||||
|
val lease =
|
||||||
|
new WriteLease[A]:
|
||||||
|
def canon: A =
|
||||||
|
A.canon
|
||||||
|
|
||||||
|
f(lease)
|
|
@ -10,6 +10,6 @@ object Load:
|
||||||
def constY[B: Encoded.Byte](x: B): Asm1[Reg.Y] =
|
def constY[B: Encoded.Byte](x: B): Asm1[Reg.Y] =
|
||||||
Const(x)
|
Const(x)
|
||||||
|
|
||||||
case class Const[R, A: Encoded.Byte](x: A)(using R: Register[R]) extends Asm1[R]:
|
case class Const[R, A](x: A)(using R: Register[R], A: Encoded.Byte[A]) extends Asm1[R]:
|
||||||
def xs: List[String] =
|
def xs: List[String] =
|
||||||
List(R.load)
|
List(s"${R.load} ${A.int(x)}")
|
||||||
|
|
|
@ -12,4 +12,4 @@ object Store:
|
||||||
|
|
||||||
case class Byte[R, A](dest: WriteLease.ByteAddress[A])(using R: Register[R]) extends Asm2[R, A]:
|
case class Byte[R, A](dest: WriteLease.ByteAddress[A])(using R: Register[R]) extends Asm2[R, A]:
|
||||||
def xs: List[String] =
|
def xs: List[String] =
|
||||||
List(R.store)
|
List(R.store + " " + dest.address)
|
||||||
|
|
|
@ -18,16 +18,24 @@ object ComplicatedResourceSuite extends FunSuite:
|
||||||
|
|
||||||
class PlayerOne extends Player[PlayerOne](40)
|
class PlayerOne extends Player[PlayerOne](40)
|
||||||
|
|
||||||
object PlayerOne extends PlayerOne:
|
object PlayerOne extends PlayerOne with GrantsWriteLeases[PlayerOne]:
|
||||||
val lease: WriteLease[PlayerOne] =
|
given Companion[PlayerOne] with
|
||||||
FastLease(PlayerOne)
|
def canon: PlayerOne =
|
||||||
|
PlayerOne
|
||||||
|
|
||||||
class PlayerTwo extends Player[PlayerTwo](80)
|
class PlayerTwo extends Player[PlayerTwo](80)
|
||||||
|
|
||||||
object PlayerTwo extends PlayerTwo:
|
object PlayerTwo extends PlayerTwo with GrantsWriteLeases[PlayerTwo]:
|
||||||
val lease: WriteLease[PlayerTwo] =
|
given Companion[PlayerTwo] with
|
||||||
FastLease(PlayerTwo)
|
def canon: PlayerTwo =
|
||||||
|
PlayerTwo
|
||||||
|
|
||||||
test("use write lease") {
|
test("use write lease") {
|
||||||
expect.eql(List("LDA", "STA"), PlayerOne.setHead(0)(using PlayerOne.lease).xs)
|
val asm =
|
||||||
|
PlayerOne
|
||||||
|
.withWriteLease { implicit w =>
|
||||||
|
PlayerOne.setHead(23).xs
|
||||||
|
}
|
||||||
|
|
||||||
|
expect.eql(List("LDA 23", "STA 40"), asm)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user