iterative support for screen

This commit is contained in:
Mark Canlas 2022-12-06 15:22:37 -05:00
parent aacc2d3afa
commit ed3b8a308d
6 changed files with 97 additions and 34 deletions

View File

@ -1,11 +1,11 @@
; $0200 = White
; Screen(0) = White
lda #$01
sta $0200
sta $200
; $0201 = Green
; Screen(1) = Green
lda #$05
sta $0201
sta $201
; $0202 = Orange
; Screen(2) = Orange
lda #$08
sta $0202
sta $202

View File

@ -0,0 +1,32 @@
; define COLOR_Black 0
; define COLOR_White 1
; define COLOR_Red 2
; define COLOR_Cyan 3
; define COLOR_Purple 4
; define COLOR_Green 5
; define COLOR_Blue 6
; define COLOR_Yellow 7
; define COLOR_Orange 8
; define COLOR_Brown 9
; define COLOR_LightRed 10
; define COLOR_DarkGrey 11
; define COLOR_Grey 12
; define COLOR_LightGreen 13
; define COLOR_LightBlue 14
; define COLOR_LightGrey 15
; define SCREEN TODO
; Screen(0) = White
LDA #COLOR_White
STA $200
; Screen(1) = Green
LDA #COLOR_Green
STA $201
; Screen(2) = Orange
LDA #COLOR_Orange
STA $202

View File

@ -16,14 +16,17 @@
; define COLOR_LightGrey 15
; $0200 = White
LDA COLOR_White
STA $0200
; define SCREEN TODO
; $0201 = Green
LDA COLOR_Green
STA $0201
; $0202 = Orange
LDA COLOR_Orange
STA $0202
; Screen(0) = White
LDA #COLOR_White
STA $200
; Screen(1) = Green
LDA #COLOR_Green
STA $201
; Screen(2) = Orange
LDA #COLOR_Orange
STA $202

View File

@ -30,3 +30,27 @@ object Easy6502:
extension (x: Color)
def toDefine: String =
"COLOR_" + x.toString
class Screen(baseAddr: Int):
def apply(offset: Int): Screen.Pixel =
Screen.Pixel(baseAddr, offset)
object Screen:
case class Pixel(baseAddr: Int, offset: Int)
object Pixel:
given Definable[Pixel] with
def table: ListMap[String, String] =
ListMap("SCREEN" -> "TODO") // define table needs to be a function of an instance
extension (x: Pixel)
def toComment: String =
s"Screen(${x.offset})"
extension (x: Pixel)
def toValue: Int =
x.baseAddr + x.offset
extension (x: Pixel)
def toDefine: String =
"TODO"

View File

@ -20,20 +20,23 @@ object PrintPrograms extends ZIOAppDefault:
private val programs =
List[(String, String)](
"one-line.txt" -> "one line",
"two-lines.txt" -> List("foo", "bar")
"one-line.txt" -> "one line",
"two-lines.txt" -> List("foo", "bar")
.pipe(Line.mkString),
"two-paragraphs.txt" -> List(
"two-paragraphs.txt" -> List(
List("foo", "bar"),
List("alpha", "bravo")
)
.pipe(xxs => AsmBlock.interFlatMap(xxs)(List("", ""), identity))
.pipe(Line.mkString),
"annotated-snake.asm" -> AnnotatedSnake.program,
"print-three-upper.asm" -> PrintThree.assemble(
"annotated-snake.asm" -> AnnotatedSnake.program,
"print-three-upper-math.asm" -> PrintThree.assemble(
AssemblerOptions(InstructionCase.Uppercase, DefinitionsMode.UseDefinitionsWithMath)
),
"print-three-upper.asm" -> PrintThree.assemble(
AssemblerOptions(InstructionCase.Uppercase, DefinitionsMode.UseDefinitions)
),
"print-three-lower.asm" -> PrintThree.assemble(
"print-three-lower.asm" -> PrintThree.assemble(
AssemblerOptions(InstructionCase.Lowercase, DefinitionsMode.UseLiterals)
)
)

View File

@ -9,19 +9,20 @@ import com.htmlism.firepower.core.AsmBlock._
import com.htmlism.firepower.core._
object PrintThree:
case class Move[A: Definable](src: A, dest: String):
def defines: Option[ListMap[String, String]] =
implicitly[Definable[A]]
.table
.some
case class Move[A: Definable, B: Definable](src: A, dest: B):
def defines: List[ListMap[String, String]] =
List(implicitly[Definable[A]].table, implicitly[Definable[B]].table)
val program: List[Move[Easy6502.Color]] =
def build(screen: Easy6502.Screen): List[Move[Easy6502.Color, Easy6502.Screen.Pixel]] =
List(
Move(Easy6502.Color.White, "$0200"),
Move(Easy6502.Color.Green, "$0201"),
Move(Easy6502.Color.Orange, "$0202")
Move(Easy6502.Color.White, screen(0)),
Move(Easy6502.Color.Green, screen(1)),
Move(Easy6502.Color.Orange, screen(2))
)
val program: List[Move[Easy6502.Color, Easy6502.Screen.Pixel]] =
build(Easy6502.Screen(200))
def assemble(opts: AssemblerOptions): String =
(defines(opts) ++ codes(opts))
.map(AsmBlock.toLines)
@ -35,7 +36,7 @@ object PrintThree:
case AssemblerOptions.DefinitionsMode.UseDefinitions =>
program
.flatMap(_.defines.toList)
.flatMap(_.defines)
.distinct
.map { xs =>
xs
@ -69,13 +70,13 @@ object PrintThree:
case AssemblerOptions.DefinitionsMode.UseDefinitions |
AssemblerOptions.DefinitionsMode.UseDefinitionsWithMath =>
mv.src.toDefine
"#" + mv.src.toDefine
AsmBlock.Intent(
s"${mv.dest} = ${mv.src.toComment}".some,
s"${mv.dest.toComment} = ${mv.src.toComment}".some,
List(
AsmBlock.Intent.Instruction(instruction("LDA", opts.instructionCase) + " " + argument, None),
AsmBlock.Intent.Instruction(instruction("STA", opts.instructionCase) + " " + mv.dest, None)
AsmBlock.Intent.Instruction(instruction("STA", opts.instructionCase) + " $" + mv.dest.toValue, None)
)
)
}