mirror of
https://github.com/mcanlas/6502-opcodes.git
synced 2024-05-28 21:41:31 +00:00
split instructions
This commit is contained in:
parent
5370ae45ee
commit
def9668d82
|
@ -71,7 +71,16 @@ object AsmBlock:
|
|||
case class Intent(label: Option[String], instructions: List[Intent.Instruction])
|
||||
|
||||
object Intent:
|
||||
case class Instruction(code: String, comment: Option[String])
|
||||
sealed trait Instruction:
|
||||
def length: Int
|
||||
|
||||
object Instruction:
|
||||
case class One(code: String, operand: String, comment: Option[String]) extends Instruction:
|
||||
def length: Int =
|
||||
operand.length + 4
|
||||
case class Zero(code: String, comment: Option[String]) extends Instruction:
|
||||
def length: Int =
|
||||
0
|
||||
|
||||
def toLines(x: Intent): List[String] =
|
||||
val comment =
|
||||
|
@ -80,19 +89,31 @@ object AsmBlock:
|
|||
val maximumLength =
|
||||
x
|
||||
.instructions
|
||||
.map(_.code.length)
|
||||
.map(_.length)
|
||||
.max
|
||||
|
||||
val instructions =
|
||||
x
|
||||
.instructions
|
||||
.map { i =>
|
||||
i.comment match
|
||||
case Some(c) =>
|
||||
String.format(s"%-${maximumLength}s", i.code) + " " + toComment(c)
|
||||
.map {
|
||||
case Instruction.Zero(code, oComment) =>
|
||||
oComment match
|
||||
case Some(c) =>
|
||||
String.format(s"%-${maximumLength}s", code) + " " + toComment(c)
|
||||
|
||||
case None =>
|
||||
i.code
|
||||
case None =>
|
||||
code
|
||||
|
||||
case Instruction.One(code, operand, oComment) =>
|
||||
val leftSlug =
|
||||
code + " " + operand
|
||||
|
||||
oComment match
|
||||
case Some(c) =>
|
||||
String.format(s"%-${maximumLength}s", leftSlug) + " " + toComment(c)
|
||||
|
||||
case None =>
|
||||
leftSlug
|
||||
}
|
||||
.map(withIndent)
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import com.htmlism.firepower.core.AsmBlock._
|
|||
|
||||
case class Subroutine(name: String, intents: List[Intent]):
|
||||
def call: Intent.Instruction =
|
||||
Intent.Instruction(s"jsr $name", None)
|
||||
Intent.Instruction.One("jsr", name, None)
|
||||
|
||||
def attach: NamedCodeBlock =
|
||||
NamedCodeBlock(name, "this is a named block".some, intents)
|
||||
|
|
|
@ -17,15 +17,15 @@ object AnnotatedSnake:
|
|||
AsmBlock.Intent(
|
||||
None,
|
||||
List(
|
||||
AsmBlock.Intent.Instruction("lda $00", None),
|
||||
AsmBlock.Intent.Instruction("lda $01", "instruction comment".some)
|
||||
AsmBlock.Intent.Instruction.One("lda", "$00", None),
|
||||
AsmBlock.Intent.Instruction.One("lda", "$01", "instruction comment".some)
|
||||
)
|
||||
),
|
||||
AsmBlock.Intent(
|
||||
"this block has some preamble".some,
|
||||
List(
|
||||
AsmBlock.Intent.Instruction("lda $00", None),
|
||||
AsmBlock.Intent.Instruction("lda $01", "instruction comment".some)
|
||||
AsmBlock.Intent.Instruction.One("lda", "$00", None),
|
||||
AsmBlock.Intent.Instruction.One("lda", "$01", "instruction comment".some)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -37,15 +37,15 @@ object AnnotatedSnake:
|
|||
AsmBlock.Intent(
|
||||
None,
|
||||
List(
|
||||
AsmBlock.Intent.Instruction("lda $00", None),
|
||||
AsmBlock.Intent.Instruction("lda $01", "instruction comment".some)
|
||||
AsmBlock.Intent.Instruction.One("lda", "$00", None),
|
||||
AsmBlock.Intent.Instruction.One("lda", "$01", "instruction comment".some)
|
||||
)
|
||||
),
|
||||
AsmBlock.Intent(
|
||||
"this block has some preamble".some,
|
||||
List(
|
||||
AsmBlock.Intent.Instruction("lda $00", None),
|
||||
AsmBlock.Intent.Instruction("lda $01", "instruction comment".some)
|
||||
AsmBlock.Intent.Instruction.One("lda", "$00", None),
|
||||
AsmBlock.Intent.Instruction.One("lda", "$01", "instruction comment".some)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
|
@ -77,11 +77,14 @@ object PrintThree:
|
|||
List(
|
||||
AsmBlock
|
||||
.Intent
|
||||
.Instruction(instruction("LDA", opts.instructionCase) + " " + argument, s"a = ${mv.src.toComment}".some),
|
||||
.Instruction
|
||||
.One(instruction("LDA", opts.instructionCase), argument, s"a = ${mv.src.toComment}".some),
|
||||
AsmBlock
|
||||
.Intent
|
||||
.Instruction(
|
||||
instruction("STA", opts.instructionCase) + " " + argumentTwo,
|
||||
.Instruction
|
||||
.One(
|
||||
instruction("STA", opts.instructionCase),
|
||||
argumentTwo,
|
||||
s"${mv.dest.toComment} = a".some
|
||||
)
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user