mirror of
https://github.com/mcanlas/6502-opcodes.git
synced 2025-01-02 17:30:44 +00:00
use table type with description
This commit is contained in:
parent
ae319b35b2
commit
d5b70c66ab
@ -1,3 +1,4 @@
|
|||||||
|
; Colors that each screen pixel can be set to
|
||||||
define COLOR_Black $00
|
define COLOR_Black $00
|
||||||
define COLOR_White $01
|
define COLOR_White $01
|
||||||
define COLOR_Red $02
|
define COLOR_Red $02
|
||||||
@ -16,6 +17,7 @@ define COLOR_LightBlue $0E
|
|||||||
define COLOR_LightGrey $0F
|
define COLOR_LightGrey $0F
|
||||||
|
|
||||||
|
|
||||||
|
; The screen as a collection of pixels
|
||||||
define SCREEN $200
|
define SCREEN $200
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
; Colors that each screen pixel can be set to
|
||||||
define COLOR_Black $00
|
define COLOR_Black $00
|
||||||
define COLOR_White $01
|
define COLOR_White $01
|
||||||
define COLOR_Red $02
|
define COLOR_Red $02
|
||||||
@ -16,6 +17,7 @@ define COLOR_LightBlue $0E
|
|||||||
define COLOR_LightGrey $0F
|
define COLOR_LightGrey $0F
|
||||||
|
|
||||||
|
|
||||||
|
; The screen as a collection of pixels
|
||||||
define SCREEN $200
|
define SCREEN $200
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,8 +21,7 @@ object AsmBlock:
|
|||||||
/**
|
/**
|
||||||
* Renders as a table of aliases
|
* Renders as a table of aliases
|
||||||
*/
|
*/
|
||||||
// TODO needs descriptive field
|
case class DefinesBlock(comment: Option[String], xs: List[(String, Int)]) extends AsmBlock
|
||||||
case class DefinesBlock(xs: List[(String, Int)]) extends AsmBlock
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders as a labeled subroutine
|
* Renders as a labeled subroutine
|
||||||
@ -70,17 +69,20 @@ object AsmBlock:
|
|||||||
case CommentBlock(ys) =>
|
case CommentBlock(ys) =>
|
||||||
ys.map(toComment)
|
ys.map(toComment)
|
||||||
|
|
||||||
case DefinesBlock(kvs) =>
|
case DefinesBlock(oComment, kvs) =>
|
||||||
val maximumLength =
|
val maximumLength =
|
||||||
kvs
|
kvs
|
||||||
.map(_._1.length)
|
.map(_._1.length)
|
||||||
.max
|
.max
|
||||||
|
|
||||||
|
val defines =
|
||||||
kvs
|
kvs
|
||||||
.map { case (k, v) =>
|
.map { case (k, v) =>
|
||||||
String.format(s"define %-${maximumLength}s ${toHex(v)}", k)
|
String.format(s"define %-${maximumLength}s ${toHex(v)}", k)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
oComment.map(toComment).toList ::: defines
|
||||||
|
|
||||||
case NamedCodeBlock(label, oComment, intents) =>
|
case NamedCodeBlock(label, oComment, intents) =>
|
||||||
val headerParagraph =
|
val headerParagraph =
|
||||||
List(label + ":") ++ oComment.map(toComment).map(withIndent).toList
|
List(label + ":") ++ oComment.map(toComment).map(withIndent).toList
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package com.htmlism.firepower.demo
|
package com.htmlism.firepower.demo
|
||||||
|
|
||||||
import scala.collection.immutable._
|
|
||||||
|
|
||||||
trait Definable[A]:
|
trait Definable[A]:
|
||||||
def table(x: A): ListMap[String, Int]
|
def table(x: A): Definable.Table
|
||||||
|
|
||||||
extension (x: A) def toComment: String
|
extension (x: A) def toComment: String
|
||||||
|
|
||||||
@ -14,5 +12,7 @@ trait Definable[A]:
|
|||||||
extension (x: A) def toDefineWithMath: String
|
extension (x: A) def toDefineWithMath: String
|
||||||
|
|
||||||
object Definable:
|
object Definable:
|
||||||
|
case class Table(description: String, xs: List[(String, Int)])
|
||||||
|
|
||||||
def apply[A](using ev: Definable[A]): Definable[A] =
|
def apply[A](using ev: Definable[A]): Definable[A] =
|
||||||
ev
|
ev
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.htmlism.firepower.demo
|
package com.htmlism.firepower.demo
|
||||||
|
|
||||||
import scala.collection.immutable._
|
|
||||||
import scala.util.chaining._
|
import scala.util.chaining._
|
||||||
|
|
||||||
object Easy6502:
|
object Easy6502:
|
||||||
@ -10,14 +9,15 @@ object Easy6502:
|
|||||||
|
|
||||||
object Color:
|
object Color:
|
||||||
given Definable[Color] with
|
given Definable[Color] with
|
||||||
def table(x: Color): ListMap[String, Int] =
|
def table(x: Color): Definable.Table =
|
||||||
Color
|
Color
|
||||||
.values
|
.values
|
||||||
.iterator
|
.iterator
|
||||||
.map { c =>
|
.map { c =>
|
||||||
"COLOR_" + c.toString -> c.ordinal
|
"COLOR_" + c.toString -> c.ordinal
|
||||||
}
|
}
|
||||||
.pipe(ListMap.from)
|
.toList
|
||||||
|
.pipe(Definable.Table("Colors that each screen pixel can be set to", _))
|
||||||
|
|
||||||
extension (x: Color)
|
extension (x: Color)
|
||||||
def toComment: String =
|
def toComment: String =
|
||||||
@ -44,8 +44,9 @@ object Easy6502:
|
|||||||
|
|
||||||
object Pixel:
|
object Pixel:
|
||||||
given Definable[Pixel] with
|
given Definable[Pixel] with
|
||||||
def table(x: Pixel): ListMap[String, Int] =
|
def table(x: Pixel): Definable.Table =
|
||||||
ListMap("SCREEN" -> x.baseAddr) // define table needs to be a function of an instance
|
// define table needs to be a function of an instance
|
||||||
|
Definable.Table("The screen as a collection of pixels", List("SCREEN" -> x.baseAddr))
|
||||||
|
|
||||||
extension (x: Pixel)
|
extension (x: Pixel)
|
||||||
def toComment: String =
|
def toComment: String =
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.htmlism.firepower.demo
|
package com.htmlism.firepower.demo
|
||||||
|
|
||||||
import scala.collection.immutable._
|
|
||||||
import scala.util.chaining._
|
import scala.util.chaining._
|
||||||
|
|
||||||
import cats.syntax.all._
|
import cats.syntax.all._
|
||||||
@ -10,7 +9,7 @@ import com.htmlism.firepower.core._
|
|||||||
|
|
||||||
object PrintThree:
|
object PrintThree:
|
||||||
case class Move[A: Definable, B: Definable](src: A, dest: B):
|
case class Move[A: Definable, B: Definable](src: A, dest: B):
|
||||||
def defines: List[ListMap[String, Int]] =
|
def defines: List[Definable.Table] =
|
||||||
List(
|
List(
|
||||||
Definable[A]
|
Definable[A]
|
||||||
.table(src),
|
.table(src),
|
||||||
@ -42,10 +41,8 @@ object PrintThree:
|
|||||||
program
|
program
|
||||||
.flatMap(_.defines)
|
.flatMap(_.defines)
|
||||||
.distinct
|
.distinct
|
||||||
.map { xs =>
|
.map { dt =>
|
||||||
xs
|
AsmBlock.DefinesBlock(dt.description.some, dt.xs)
|
||||||
.toList
|
|
||||||
.pipe(AsmBlock.DefinesBlock(_))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private def codes(opts: AssemblerOptions.DefinitionsMode) =
|
private def codes(opts: AssemblerOptions.DefinitionsMode) =
|
||||||
|
Loading…
Reference in New Issue
Block a user