enable case configuration

This commit is contained in:
Mark Canlas 2022-12-06 13:43:48 -05:00
parent fe03739c48
commit 8c3d8a2bd3
5 changed files with 52 additions and 33 deletions

View File

@ -0,0 +1,8 @@
lda #$01
sta $0200
lda #$03
sta $0201
lda #$05
sta $0202

View File

@ -1,8 +1,8 @@
LDA #$01
STA $0200
LDA #$05
LDA #$03
STA $0201
LDA #$08
LDA #$05
STA $0202

View File

@ -1,6 +1,9 @@
package com.htmlism.firepower.core
case class AssemblerOptions(instructionCase: AssemblerOptions.InstructionCase, definitionsMode: AssemblerOptions.DefinitionsMode)
case class AssemblerOptions(
instructionCase: AssemblerOptions.InstructionCase,
definitionsMode: AssemblerOptions.DefinitionsMode
)
object AssemblerOptions:
enum DefinitionsMode:

View File

@ -8,6 +8,7 @@ import cats.syntax.all._
import zio.*
import com.htmlism.firepower.core.AsmBlock._
import com.htmlism.firepower.core.AssemblerOptions._
import com.htmlism.firepower.core._
import com.htmlism.firepower.demo.str._
import com.htmlism.rufio.withzio.*
@ -19,17 +20,22 @@ 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.asm" -> PrintThree.program
"annotated-snake.asm" -> AnnotatedSnake.program,
"print-three-upper.asm" -> PrintThree.assemble(
AssemblerOptions(InstructionCase.Uppercase, DefinitionsMode.InlineDefinitions)
),
"print-three-lower.asm" -> PrintThree.assemble(
AssemblerOptions(InstructionCase.Lowercase, DefinitionsMode.InlineDefinitions)
)
)
def run: Task[Unit] =

View File

@ -8,34 +8,36 @@ import com.htmlism.firepower.core.AsmBlock._
import com.htmlism.firepower.core._
object PrintThree:
val program: String =
case class Move(src: String, dest: String)
val program: List[Move] =
List(
AnonymousCodeBlock(
List(
AsmBlock.Intent(
None,
List(
AsmBlock.Intent.Instruction("LDA #$01", None),
AsmBlock.Intent.Instruction("STA $0200", None)
)
),
AsmBlock.Intent(
None,
List(
AsmBlock.Intent.Instruction("LDA #$05", None),
AsmBlock.Intent.Instruction("STA $0201", None)
)
),
AsmBlock.Intent(
None,
List(
AsmBlock.Intent.Instruction("LDA #$08", None),
AsmBlock.Intent.Instruction("STA $0202", None)
)
Move("#$01", "$0200"),
Move("#$03", "$0201"),
Move("#$05", "$0202")
)
def assemble(opt: AssemblerOptions): String =
program
.map { mv =>
AsmBlock.Intent(
None,
List(
AsmBlock.Intent.Instruction(instruction("LDA", opt.instructionCase) + " " + mv.src, None),
AsmBlock.Intent.Instruction(instruction("STA", opt.instructionCase) + " " + mv.dest, None)
)
)
)
)
}
.pipe(AnonymousCodeBlock(_))
.pipe(List(_))
.map(AsmBlock.toLines)
.pipe(xs => AsmBlock.interFlatMap(xs)(List("", ""), identity))
.pipe(str.Line.mkString)
def instruction(s: String, instructionCase: AssemblerOptions.InstructionCase): String =
instructionCase match
case AssemblerOptions.InstructionCase.Uppercase =>
s.toUpperCase
case AssemblerOptions.InstructionCase.Lowercase =>
s.toLowerCase