shithub: orca

Download patch

ref: 903f9b50e3ebcef4d79c678c4a2fe3e053ad7896
parent: 428edd25676d0142b85aa30fe46014409fb73e65
author: cancel <[email protected]>
date: Wed Nov 28 10:36:13 EST 2018

Fix indexing mistakes, add 'X'

--- a/bank.c
+++ b/bank.c
@@ -10,7 +10,7 @@
 }
 ORCA_FORCE_STATIC_INLINE
 Usz bank_entry_size(Usz glyph_count) {
-  return ORCA_BANK_ENTRY_HEADER + bank_entry_padding(glyph_count);
+  return ORCA_BANK_ENTRY_HEADER + glyph_count + bank_entry_padding(glyph_count);
 }
 
 void bank_init(Bank* bank) {
@@ -43,7 +43,7 @@
   Usz new_size = cur_size + bank_entry_size(glyph_count);
   if (new_size > bank->capacity)
     bank_enlarge_to(bank, new_size);
-  char* data = bank->data;
+  char* data = bank->data + cur_size;
   Bank_entry* entry =
       (Bank_entry*)ORCA_ASSUME_ALIGNED(data, ORCA_BANK_ENTRY_ALIGN);
   entry->index = (U32)index;
@@ -77,7 +77,8 @@
     goto fail;
   entry_size = entry->size;
   if (entry_index < index) {
-    offset += ORCA_BANK_ENTRY_HEADER + entry_size;
+    offset +=
+        ORCA_BANK_ENTRY_HEADER + entry_size + bank_entry_padding(entry_size);
     goto next;
   }
   num_to_copy = dest_count < entry_size ? dest_count : entry_size;
@@ -84,7 +85,8 @@
   memcpy(dest, bank_data + offset + ORCA_BANK_ENTRY_HEADER, num_to_copy);
   if (num_to_copy < dest_count)
     memset(dest, '.', dest_count - num_to_copy);
-  *cursor = ORCA_BANK_ENTRY_HEADER + entry_size;
+  *cursor = offset + ORCA_BANK_ENTRY_HEADER + entry_size +
+            bank_entry_padding(entry_size);
   return num_to_copy;
 
 fail:
--- a/sim.c
+++ b/sim.c
@@ -268,7 +268,8 @@
   _('I', 'i', increment)                                                       \
   _('J', 'j', jump)                                                            \
   _('M', 'm', modulo)                                                          \
-  _('O', 'o', offset)
+  _('O', 'o', offset)                                                          \
+  _('X', 'x', teleport)
 
 ORCA_DECLARE_OPERATORS(ORCA_SOLO_OPERATORS, ORCA_DUAL_OPERATORS)
 
@@ -381,7 +382,7 @@
     coords[1] = PEEK(0, -2);
     STORE(coords);
     read_y = UCLAMP(INDEX(coords[0]), 0, 16);
-    read_x = UCLAMP(INDEX(coords[0]) + 1, 1, 16);
+    read_x = UCLAMP(INDEX(coords[1]) + 1, 1, 16);
   }
   BEGIN_DUAL_PORTS
     I_PORT(0, -1, LOCKING | HASTE);
@@ -402,6 +403,38 @@
   }
   POKE(1, 0, PEEK(read_y, read_x));
   STUN(0, 1);
+END_PHASE
+
+BEGIN_DUAL_PHASE_0(teleport)
+  REALIZE_DUAL;
+  Usz write_y = 0;
+  Usz write_x = 1;
+  if (DUAL_IS_ACTIVE) {
+    Glyph coords[2];
+    coords[0] = PEEK(0, -1);
+    coords[1] = PEEK(0, -2);
+    STORE(coords);
+    write_y = UCLAMP(INDEX(coords[0]), 0, 16);
+    write_x = UCLAMP(INDEX(coords[1]), 1, 16);
+  }
+  BEGIN_DUAL_PORTS
+    I_PORT(0, -1, LOCKING | HASTE);
+    I_PORT(0, -2, LOCKING | HASTE);
+    I_PORT(1, 0, LOCKING);
+    O_PORT((Isz)write_y, (Isz)write_x, NONLOCKING);
+  END_PORTS
+END_PHASE
+BEGIN_DUAL_PHASE_1(teleport)
+  STOP_IF_NOT_BANGED;
+  Isz write_y = 0;
+  Isz write_x = 1;
+  Glyph coords[2];
+  if (LOAD(coords)) {
+    write_y = (Isz)UCLAMP(INDEX(coords[0]), 0, 16);
+    write_x = (Isz)UCLAMP(INDEX(coords[1]), 1, 16);
+  }
+  POKE(write_y, write_x, PEEK(0, 1));
+  STUN(write_y, write_x);
 END_PHASE
 
 //////// Run simulation