From 5370ae45ee541e43a2a5dd29862757dbed010243 Mon Sep 17 00:00:00 2001 From: Mark Canlas Date: Tue, 6 Dec 2022 17:20:30 -0500 Subject: [PATCH] with uneven comments --- data/print-three-lower.asm | 12 ++++----- data/print-three-upper-math.asm | 12 ++++----- data/print-three-upper.asm | 12 ++++----- .../com/htmlism/firepower/core/AsmBlock.scala | 27 ++++++++++++++++--- .../htmlism/firepower/demo/PrintThree.scala | 9 +++++-- 5 files changed, 48 insertions(+), 24 deletions(-) diff --git a/data/print-three-lower.asm b/data/print-three-lower.asm index f7b548b..3a02437 100644 --- a/data/print-three-lower.asm +++ b/data/print-three-lower.asm @@ -1,11 +1,11 @@ ; Screen(0) = White - lda #$01 - sta $200 + lda #$01 ; a = White + sta $200 ; Screen(0) = a ; Screen(1) = Green - lda #$05 - sta $201 + lda #$05 ; a = Green + sta $201 ; Screen(1) = a ; Screen(2) = Orange - lda #$08 - sta $202 + lda #$08 ; a = Orange + sta $202 ; Screen(2) = a diff --git a/data/print-three-upper-math.asm b/data/print-three-upper-math.asm index ebd26cf..cc9dacf 100644 --- a/data/print-three-upper-math.asm +++ b/data/print-three-upper-math.asm @@ -20,13 +20,13 @@ define SCREEN $200 ; Screen(0) = White - LDA #COLOR_White - STA SCREEN+0 + LDA #COLOR_White ; a = White + STA SCREEN+0 ; Screen(0) = a ; Screen(1) = Green - LDA #COLOR_Green - STA SCREEN+1 + LDA #COLOR_Green ; a = Green + STA SCREEN+1 ; Screen(1) = a ; Screen(2) = Orange - LDA #COLOR_Orange - STA SCREEN+2 + LDA #COLOR_Orange ; a = Orange + STA SCREEN+2 ; Screen(2) = a diff --git a/data/print-three-upper.asm b/data/print-three-upper.asm index 5d53640..08952b9 100644 --- a/data/print-three-upper.asm +++ b/data/print-three-upper.asm @@ -20,13 +20,13 @@ define SCREEN $200 ; Screen(0) = White - LDA #COLOR_White - STA SCREEN + LDA #COLOR_White ; a = White + STA SCREEN ; Screen(0) = a ; Screen(1) = Green - LDA #COLOR_Green - STA TODO + LDA #COLOR_Green ; a = Green + STA TODO ; Screen(1) = a ; Screen(2) = Orange - LDA #COLOR_Orange - STA TODO + LDA #COLOR_Orange ; a = Orange + STA TODO ; Screen(2) = a diff --git a/firepower-core/src/main/scala/com/htmlism/firepower/core/AsmBlock.scala b/firepower-core/src/main/scala/com/htmlism/firepower/core/AsmBlock.scala index af7cc88..0ab3e93 100644 --- a/firepower-core/src/main/scala/com/htmlism/firepower/core/AsmBlock.scala +++ b/firepower-core/src/main/scala/com/htmlism/firepower/core/AsmBlock.scala @@ -74,7 +74,26 @@ object AsmBlock: case class Instruction(code: String, comment: Option[String]) def toLines(x: Intent): List[String] = - x.label.map(toComment).map(withIndent).toList ++ x - .instructions - .map(i => i.code + i.comment.map(toComment).map(" " + _).getOrElse("")) - .map(withIndent) + val comment = + x.label.map(toComment).map(withIndent).toList + + val maximumLength = + x + .instructions + .map(_.code.length) + .max + + val instructions = + x + .instructions + .map { i => + i.comment match + case Some(c) => + String.format(s"%-${maximumLength}s", i.code) + " " + toComment(c) + + case None => + i.code + } + .map(withIndent) + + comment ++ instructions diff --git a/firepower-demo/src/main/scala/com/htmlism/firepower/demo/PrintThree.scala b/firepower-demo/src/main/scala/com/htmlism/firepower/demo/PrintThree.scala index c254fe9..c2994e9 100644 --- a/firepower-demo/src/main/scala/com/htmlism/firepower/demo/PrintThree.scala +++ b/firepower-demo/src/main/scala/com/htmlism/firepower/demo/PrintThree.scala @@ -75,10 +75,15 @@ object PrintThree: AsmBlock.Intent( 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) + " " + argumentTwo, None) + .Instruction(instruction("LDA", opts.instructionCase) + " " + argument, s"a = ${mv.src.toComment}".some), + AsmBlock + .Intent + .Instruction( + instruction("STA", opts.instructionCase) + " " + argumentTwo, + s"${mv.dest.toComment} = a".some + ) ) ) }