mirror of
https://github.com/mcanlas/6502-opcodes.git
synced 2025-01-02 02:31:38 +00:00
definable
This commit is contained in:
parent
aad7c33c42
commit
899d36f7fe
@ -1,11 +1,11 @@
|
|||||||
; $0200 = #$01
|
; $0200 = White
|
||||||
lda #$01
|
lda #$01
|
||||||
sta $0200
|
sta $0200
|
||||||
|
|
||||||
; $0201 = #$03
|
; $0201 = Green
|
||||||
lda #$03
|
lda #$05
|
||||||
sta $0201
|
sta $0201
|
||||||
|
|
||||||
; $0202 = #$05
|
; $0202 = Orange
|
||||||
lda #$05
|
lda #$08
|
||||||
sta $0202
|
sta $0202
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
; $0200 = #$01
|
; $0200 = White
|
||||||
LDA #$01
|
LDA #$01
|
||||||
STA $0200
|
STA $0200
|
||||||
|
|
||||||
; $0201 = #$03
|
; $0201 = Green
|
||||||
LDA #$03
|
LDA #$05
|
||||||
STA $0201
|
STA $0201
|
||||||
|
|
||||||
; $0202 = #$05
|
; $0202 = Orange
|
||||||
LDA #$05
|
LDA #$08
|
||||||
STA $0202
|
STA $0202
|
||||||
|
@ -7,7 +7,7 @@ case class AssemblerOptions(
|
|||||||
|
|
||||||
object AssemblerOptions:
|
object AssemblerOptions:
|
||||||
enum DefinitionsMode:
|
enum DefinitionsMode:
|
||||||
case InlineDefinitions, UseDefinitions, UseDefinitionsWithMath
|
case UseLiterals, UseDefinitions, UseDefinitionsWithMath
|
||||||
|
|
||||||
enum InstructionCase:
|
enum InstructionCase:
|
||||||
case Uppercase, Lowercase
|
case Uppercase, Lowercase
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
package com.htmlism.firepower.demo
|
||||||
|
|
||||||
|
trait Definable[A]:
|
||||||
|
extension (x: A) def toComment: String
|
||||||
|
|
||||||
|
extension (x: A) def toValue: Int
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.htmlism.firepower.demo
|
||||||
|
|
||||||
|
object Easy6502:
|
||||||
|
enum Color:
|
||||||
|
case Black, White, Red, Cyan, Purple, Green, Blue, Yellow, Orange, Brown, LightRed, DarkGrey, Grey, LightGreen,
|
||||||
|
LightBlue, LightGrey
|
||||||
|
|
||||||
|
object Color:
|
||||||
|
given Definable[Color] with
|
||||||
|
extension (x: Color)
|
||||||
|
def toComment: String =
|
||||||
|
x.toString
|
||||||
|
|
||||||
|
extension (x: Color)
|
||||||
|
def toValue: Int =
|
||||||
|
x.ordinal
|
@ -31,10 +31,10 @@ object PrintPrograms extends ZIOAppDefault:
|
|||||||
.pipe(Line.mkString),
|
.pipe(Line.mkString),
|
||||||
"annotated-snake.asm" -> AnnotatedSnake.program,
|
"annotated-snake.asm" -> AnnotatedSnake.program,
|
||||||
"print-three-upper.asm" -> PrintThree.assemble(
|
"print-three-upper.asm" -> PrintThree.assemble(
|
||||||
AssemblerOptions(InstructionCase.Uppercase, DefinitionsMode.InlineDefinitions)
|
AssemblerOptions(InstructionCase.Uppercase, DefinitionsMode.UseLiterals)
|
||||||
),
|
),
|
||||||
"print-three-lower.asm" -> PrintThree.assemble(
|
"print-three-lower.asm" -> PrintThree.assemble(
|
||||||
AssemblerOptions(InstructionCase.Lowercase, DefinitionsMode.InlineDefinitions)
|
AssemblerOptions(InstructionCase.Lowercase, DefinitionsMode.UseLiterals)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -8,22 +8,25 @@ import com.htmlism.firepower.core.AsmBlock._
|
|||||||
import com.htmlism.firepower.core._
|
import com.htmlism.firepower.core._
|
||||||
|
|
||||||
object PrintThree:
|
object PrintThree:
|
||||||
case class Move(src: String, dest: String)
|
case class Move[A: Definable](src: A, dest: String)
|
||||||
|
|
||||||
val program: List[Move] =
|
val program: List[Move[Easy6502.Color]] =
|
||||||
List(
|
List(
|
||||||
Move("#$01", "$0200"),
|
Move(Easy6502.Color.White, "$0200"),
|
||||||
Move("#$03", "$0201"),
|
Move(Easy6502.Color.Green, "$0201"),
|
||||||
Move("#$05", "$0202")
|
Move(Easy6502.Color.Orange, "$0202")
|
||||||
)
|
)
|
||||||
|
|
||||||
def assemble(opt: AssemblerOptions): String =
|
def assemble(opt: AssemblerOptions): String =
|
||||||
program
|
program
|
||||||
.map { mv =>
|
.map { mv =>
|
||||||
|
val hex =
|
||||||
|
f"#$$${mv.src.toValue}%02X"
|
||||||
|
|
||||||
AsmBlock.Intent(
|
AsmBlock.Intent(
|
||||||
s"${mv.dest} = ${mv.src}".some,
|
s"${mv.dest} = ${mv.src.toComment}".some,
|
||||||
List(
|
List(
|
||||||
AsmBlock.Intent.Instruction(instruction("LDA", opt.instructionCase) + " " + mv.src, None),
|
AsmBlock.Intent.Instruction(instruction("LDA", opt.instructionCase) + " " + hex, None),
|
||||||
AsmBlock.Intent.Instruction(instruction("STA", opt.instructionCase) + " " + mv.dest, None)
|
AsmBlock.Intent.Instruction(instruction("STA", opt.instructionCase) + " " + mv.dest, None)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user