diff --git a/src/main/scala/millfork/env/Constant.scala b/src/main/scala/millfork/env/Constant.scala index 51b05e6d..22b4006c 100644 --- a/src/main/scala/millfork/env/Constant.scala +++ b/src/main/scala/millfork/env/Constant.scala @@ -66,7 +66,7 @@ sealed trait Constant { } def subbyte(index: Int): Constant = { - if (requiredSize <= index) Constant.Zero + if (requiredSize > 0 && requiredSize <= index) Constant.Zero else index match { case 0 => if (isProvablyDivisibleBy256) Constant.Zero else loByte case 1 => hiByte diff --git a/src/test/scala/millfork/test/StructSuite.scala b/src/test/scala/millfork/test/StructSuite.scala index cf591e55..f9dce740 100644 --- a/src/test/scala/millfork/test/StructSuite.scala +++ b/src/test/scala/millfork/test/StructSuite.scala @@ -176,4 +176,30 @@ class StructSuite extends FunSuite with Matchers { m.readWord(0xc002) should equal(code.count(_ == '↑') + 8) } } + + + test("Boolean fields") { + val code = + """ + |struct Sprite { + | byte size, + | byte size2, + | byte size3, + | byte size4, + | bool x1, + | bool x, + | bool y, + | bool z + |} + | + |array(Sprite) sprites [20] @ $c000 + | + |void main() { + | sprites[0].x = true + |} + |""".stripMargin + EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8086, Cpu.Motorola6809)(code){ m => + m.readByte(0xc005) should equal(1) + } + } }