From 1beb69515118296c1ac7363c3b4f73b961dc8570 Mon Sep 17 00:00:00 2001 From: Karol Stasiak Date: Fri, 27 Jan 2023 18:16:36 +0100 Subject: [PATCH] more tests --- src/test/scala/millfork/test/ArraySuite.scala | 17 +++++++++++++ .../scala/millfork/test/StructSuite.scala | 24 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/test/scala/millfork/test/ArraySuite.scala b/src/test/scala/millfork/test/ArraySuite.scala index 58f430d6..b73e21d3 100644 --- a/src/test/scala/millfork/test/ArraySuite.scala +++ b/src/test/scala/millfork/test/ArraySuite.scala @@ -714,4 +714,21 @@ class ArraySuite extends FunSuite with Matchers with AppendedClues { m.readByte(0x4008) should equal('9'.toInt) } } + + test("Arrays of pointers") { + EmuUnoptimizedCrossPlatformRun(Cpu.Mos)( + """ + |const array arr1 = [1, 2, 3] + |const array arr2 = [101, 102, 103] + |array(pointer) arrs = [ arr1, arr2 ] + |byte output @$c000 + |void main() { + | pointer p + | p = arrs[1] + | output = p[0] + |} + """.stripMargin) { m => + m.readByte(0xc000) should equal(101) + } + } } diff --git a/src/test/scala/millfork/test/StructSuite.scala b/src/test/scala/millfork/test/StructSuite.scala index f9a4d749..cb259643 100644 --- a/src/test/scala/millfork/test/StructSuite.scala +++ b/src/test/scala/millfork/test/StructSuite.scala @@ -362,4 +362,28 @@ class StructSuite extends FunSuite with Matchers { | } |""".stripMargin){m => } } + + test("Assigning struct fields via pointers") { + EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8086, Cpu.Motorola6809)(""" + struct STRUCT1 { word a } + struct STRUCT2 { word b } + pointer.STRUCT1 pS1 + pointer.STRUCT2 pS2 + STRUCT1 s1 @$c000 + STRUCT2 s2 + + noinline void f() { + pS1->a = pS2->b + } + + void main() { + s2.b = $405 + pS1 = s1.pointer + pS2 = s2.pointer + f() + } + """){m => + m.readWord(0xc000) should equal(0x405) + } + } }