X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=interpreters%2Fbocfel%2Ftable.c;fp=interpreters%2Fbocfel%2Ftable.c;h=1de5e9e35fd62b52674f835aa416a3cce154dd91;hb=3c59ba5eef5cb4d39c06eb7f523b9c3b026bdc9b;hp=0000000000000000000000000000000000000000;hpb=ed91d840318ed6ebfe3a5a77fa17114ddbf56640;p=projects%2Fchimara%2Fchimara.git
diff --git a/interpreters/bocfel/table.c b/interpreters/bocfel/table.c
new file mode 100644
index 0000000..1de5e9e
--- /dev/null
+++ b/interpreters/bocfel/table.c
@@ -0,0 +1,90 @@
+/*-
+ * Copyright 2010-2012 Chris Spiegel.
+ *
+ * This file is part of Bocfel.
+ *
+ * Bocfel is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version
+ * 2 or 3, as published by the Free Software Foundation.
+ *
+ * Bocfel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Bocfel. If not, see .
+ */
+
+#include
+#include
+
+#include "table.h"
+#include "branch.h"
+#include "memory.h"
+#include "process.h"
+#include "zterp.h"
+
+void zcopy_table(void)
+{
+ uint16_t first = zargs[0], second = zargs[1], size = zargs[2];
+
+ if(second == 0)
+ {
+ for(uint16_t i = 0; i < size; i++) user_store_byte(first + i, 0);
+ }
+ else if( (first > second) || (int16_t)size < 0 )
+ {
+ long n = labs((int16_t)size);
+ for(long i = 0; i < n; i++) user_store_byte(second + i, user_byte(first + i));
+ }
+ else
+ {
+ for(uint16_t i = 0; i < size; i++) user_store_byte(second + size - i - 1, user_byte(first + size - i - 1));
+ }
+}
+
+void zscan_table(void)
+{
+ uint16_t addr = zargs[1];
+
+ if(znargs < 4) zargs[3] = 0x82;
+
+ for(uint16_t i = 0; i < zargs[2]; i++)
+ {
+ if(
+ ( (zargs[3] & 0x80) && (user_word(addr) == zargs[0])) ||
+ (!(zargs[3] & 0x80) && (user_byte(addr) == zargs[0]))
+ )
+ {
+ store(addr);
+ branch_if(1);
+ return;
+ }
+
+ addr += zargs[3] & 0x7f;
+ }
+
+ store(0);
+ branch_if(0);
+}
+
+void zloadw(void)
+{
+ store(user_word(zargs[0] + (2 * zargs[1])));
+}
+
+void zloadb(void)
+{
+ store(user_byte(zargs[0] + zargs[1]));
+}
+
+void zstoreb(void)
+{
+ user_store_byte(zargs[0] + zargs[1], zargs[2]);
+}
+
+void zstorew(void)
+{
+ user_store_word(zargs[0] + (2 * zargs[1]), zargs[2]);
+}