Implement more statements and ignore some I/O related ones, LEMONADE can run
authorNick Downing <nick@ndcode.org>
Tue, 17 May 2022 14:11:36 +0000 (00:11 +1000)
committerNick Downing <nick@ndcode.org>
Tue, 17 May 2022 14:11:46 +0000 (00:11 +1000)
apple_io.py
applesoft_basic.l
applesoft_basic.t
applesoft_basic.y

index a2a9274..267ddcf 100755 (executable)
@@ -149,7 +149,9 @@ poll_in = select.poll()
 poll_in.register(fd_in, select.POLLIN)
 mem = {
   ZP_CH: 0,
-  ZP_CV: 0
+  ZP_CV: 0,
+  0x300: 0, # tone freq
+  0x301: 0, # tone dur
 }
 
 def init():
@@ -168,6 +170,12 @@ def deinit():
     atexit.unregister(deinit)
     attr = None
 
+def pr_hash(n):
+  pass
+
+def in_hash(n):
+  pass
+
 def read_ready():
   return len(poll_in.poll(1)) != 0
 
@@ -216,7 +224,7 @@ def input():
       return line
     if ch == '\b':
       if len(line):
-        _prnt(' \b')
+        _print(' \b')
         line = line[:-1]
       else:
         # strictly, apple only does this if cursor not at left, maybe
@@ -260,6 +268,12 @@ def tone(freq, dur): # Hz, ms
   # doesn't seem to work on any linux console on my laptop
   write(f'\x1b7\x1b[10;{freq:d}]\x1b[11;{dur:d}]\x07\x1b8')
 
+def himem(addr):
+  pass
+
+def lomem(addr):
+  pass
+
 def peek(addr):
   return mem.get(addr & 0xffff, 0)
 
@@ -268,7 +282,18 @@ def poke(addr, data):
 
 def call(addr):
   addr &= 0xffff
-  raise Exception(f'call {addr:04x}')
+  if addr == 0x302:
+    tone(mem[0x300], mem[0x301])
+  elif addr == 0x3600:
+    # lighting (setup)
+    pass
+  elif addr == 0x3603:
+    # lightning (execute)
+    pass
+  elif addr == ROM_CLREOP:
+    clreop()
+  else:
+    raise Exception(f'call {addr:04x}')
 
 def text():
   pass
index 578bd35..d24224a 100644 (file)
   }
 }
 <INITIAL>{
-  \>\ *=|=\ *\> {
+  \xcf\ *\xd0|\xd0\ *\xcf {
     return y_tab.OPERATOR_GE
   }
-  \<\ *=|=\ *\< {
+  \xd1\ *\xd0|\xd0\ *\xd1 {
     return y_tab.OPERATOR_LE
   }
-  \<\ *\>|\>\ *\< {
+  \xd1\ *\xcf|\xcf\ *\xd1 {
     return y_tab.OPERATOR_NE
   }
 }
index beb5de0..55aebbe 100644 (file)
@@ -445,10 +445,12 @@ def execute(self, context):
   apple_io.text()
 @method(StatementPrHash)
 def execute(self, context):
-  assert False
+  value = self.children[0].get_int(context)
+  apple_io.pr_hash(value)
 @method(StatementInHash)
 def execute(self, context):
-  assert False
+  value = self.children[0].get_int(context)
+  apple_io.in_hash(value)
 @method(StatementCall)
 def execute(self, context):
   value = self.children[0].get_int(context)
@@ -532,10 +534,12 @@ def execute(self, context):
   apple_io.vtab(value)
 @method(StatementHimemColon)
 def execute(self, context):
-  assert False
+  value = self.children[0].get_int(context)
+  apple_io.himem(value)
 @method(StatementLomemColon)
 def execute(self, context):
-  assert False
+  value = self.children[0].get_int(context)
+  apple_io.lomem(value)
 @method(StatementOnErr)
 def execute(self, context):
   assert False
index f4c2058..0d1ca43 100644 (file)
@@ -179,8 +179,8 @@ statement_opt
   | %space (?E{t_def.StatementRead}TOKEN_READ lvalue_list)
   | %space (?E{t_def.StatementGr}TOKEN_GR)
   | %space (?E{t_def.StatementText}TOKEN_TEXT)
-  | %space (?E{t_def.StatementPrHash}TOKEN_PR_HASH)
-  | %space (?E{t_def.StatementInHash}TOKEN_IN_HASH)
+  | %space (?E{t_def.StatementPrHash}TOKEN_PR_HASH rvalue)
+  | %space (?E{t_def.StatementInHash}TOKEN_IN_HASH rvalue)
   | %space (?E{t_def.StatementCall}TOKEN_CALL rvalue)
   | %space (?E{t_def.StatementPlot}TOKEN_PLOT rvalue ',' rvalue)
   | %space (?E{t_def.StatementHLin}TOKEN_HLIN rvalue ',' rvalue TOKEN_AT rvalue)
@@ -204,8 +204,8 @@ statement_opt
   | %space (?E{t_def.StatementColorEqual}TOKEN_COLOR_EQUAL rvalue)
   | %space (?E{t_def.StatementPop}TOKEN_POP)
   | %space (?E{t_def.StatementVTab}TOKEN_VTAB rvalue)
-  | %space (?E{t_def.StatementHimemColon}TOKEN_HIMEM_COLON)
-  | %space (?E{t_def.StatementLomemColon}TOKEN_LOMEM_COLON)
+  | %space (?E{t_def.StatementHimemColon}TOKEN_HIMEM_COLON rvalue)
+  | %space (?E{t_def.StatementLomemColon}TOKEN_LOMEM_COLON rvalue)
   | %space (?E{t_def.StatementOnErr}TOKEN_ONERR)
   | %space (?E{t_def.StatementResume}TOKEN_RESUME)
   | %space (?E{t_def.StatementRecall}TOKEN_RECALL)