Implement a heuristic to detect delay loops, can now play unpatched lemonade
authorNick Downing <nick@ndcode.org>
Tue, 24 May 2022 04:39:13 +0000 (14:39 +1000)
committerNick Downing <nick@ndcode.org>
Tue, 24 May 2022 07:32:10 +0000 (17:32 +1000)
applesoft_basic.t

index 2e35683..84df4f8 100644 (file)
@@ -348,6 +348,31 @@ def execute(self, context):
     1.
   )
 
+  # heuristically detect delay loops
+  if step != 0.:
+    i = context.i
+    j = context.j
+    while i < len(context.program.children):
+      line = context.program.children[i]
+      if j < len(line.children):
+        statement = line.children[j]
+        j += 1
+        if (
+          isinstance(statement, StatementNext) and (
+            len(statement.children) < 1 or
+              statement.children[0].str_value == name
+          )
+        ):
+          counts = math.floor((end - variable.value) / step) + 1
+          time.sleep(counts / 1080.)
+          context.i = i
+          context.j = j
+          return
+        break
+      else:
+        i += 1
+        j = 1
+
   i = context.i
   j = context.j
   while True: