diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/evolver.h | 17 | ||||
-rw-r--r-- | include/instset.h | 93 | ||||
-rw-r--r-- | include/memory.h | 30 | ||||
-rw-r--r-- | include/process.h | 40 | ||||
-rw-r--r-- | include/salis.h | 22 | ||||
-rw-r--r-- | include/types.h | 31 |
6 files changed, 233 insertions, 0 deletions
diff --git a/include/evolver.h b/include/evolver.h new file mode 100644 index 0000000..15a4f64 --- /dev/null +++ b/include/evolver.h @@ -0,0 +1,17 @@ +#ifndef SALIS_EVOLVER_H
+#define SALIS_EVOLVER_H
+
+void se_init (void);
+void se_quit (void);
+void se_load (FILE *file);
+void se_save (FILE *file);
+
+sbool se_isInit (void);
+sword se_getLastAddress (void);
+sbyte se_getLastInst (void);
+sword se_getState (sword eidx);
+void se_setState (sword eidx, sword state);
+
+void se_cycle (void);
+
+#endif
diff --git a/include/instset.h b/include/instset.h new file mode 100644 index 0000000..e819ff3 --- /dev/null +++ b/include/instset.h @@ -0,0 +1,93 @@ +#ifndef SALIS_INSTSET_H
+#define SALIS_INSTSET_H
+
+#define SINST_COUNT 64
+
+#define SINST_LIST \
+ SINST(SNOOP, ' ') \
+ SINST(SNOP0, '0') \
+ SINST(SNOP1, '1') \
+ SINST(SNOP2, '2') \
+ SINST(SNOP3, '3') \
+ \
+ SINST(SJMPB, '(') \
+ SINST(SJMPF, ')') \
+ SINST(SADRB, '[') \
+ SINST(SADRF, ']') \
+ SINST(SIFNZ, '?') \
+ \
+ SINST(SALLB, '{') \
+ SINST(SALLF, '}') \
+ SINST(SBSWP, '%') \
+ SINST(SBCLR, '|') \
+ SINST(SSPLT, '$') \
+ \
+ SINST(SADDN, '+') \
+ SINST(SSUBN, '-') \
+ SINST(SMULN, '*') \
+ SINST(SDIVN, '/') \
+ SINST(SINCN, '^') \
+ SINST(SDECN, 'v') \
+ SINST(SNOTN, '!') \
+ SINST(SSHFL, '<') \
+ SINST(SSHFR, '>') \
+ SINST(SZERO, 'z') \
+ SINST(SUNIT, 'u') \
+ \
+ SINST(SPSHN, '#') \
+ SINST(SPOPN, '~') \
+ \
+ SINST(SLOAD, '.') \
+ SINST(SWRTE, ':') \
+ SINST(SDUPL, '"') \
+ SINST(SSWAP, 'x') \
+ \
+ SINST(SKEYA, 'a') \
+ SINST(SKEYB, 'b') \
+ SINST(SKEYC, 'c') \
+ SINST(SKEYD, 'd') \
+ SINST(SKEYE, 'e') \
+ SINST(SKEYF, 'f') \
+ SINST(SKEYG, 'g') \
+ SINST(SKEYH, 'h') \
+ SINST(SKEYI, 'i') \
+ SINST(SKEYJ, 'j') \
+ SINST(SKEYK, 'k') \
+ SINST(SKEYL, 'l') \
+ SINST(SKEYM, 'm') \
+ SINST(SKEYN, 'n') \
+ SINST(SKEYO, 'o') \
+ SINST(SKEYP, 'p') \
+ \
+ SINST(SLOKA, 'A') \
+ SINST(SLOKB, 'B') \
+ SINST(SLOKC, 'C') \
+ SINST(SLOKD, 'D') \
+ SINST(SLOKE, 'E') \
+ SINST(SLOKF, 'F') \
+ SINST(SLOKG, 'G') \
+ SINST(SLOKH, 'H') \
+ SINST(SLOKI, 'I') \
+ SINST(SLOKJ, 'J') \
+ SINST(SLOKK, 'K') \
+ SINST(SLOKL, 'L') \
+ SINST(SLOKM, 'M') \
+ SINST(SLOKN, 'N') \
+ SINST(SLOKO, 'O') \
+ SILST(SLOKP, 'P')
+
+enum sinst {
+#define SINST(name, symb) name,
+#define SILST(name, symb) name
+ SINST_LIST
+#undef SINST
+#undef SILST
+};
+
+sbool si_isInst (sbyte inst);
+sbool si_isMod (sbyte inst);
+sbool si_isKey (sbyte inst);
+sbool si_isLock (sbyte inst);
+sbool si_keyLockMatch (sbyte key, sbyte lock);
+
+#endif
diff --git a/include/memory.h b/include/memory.h new file mode 100644 index 0000000..a36a2ff --- /dev/null +++ b/include/memory.h @@ -0,0 +1,30 @@ +#ifndef SALIS_MEMORY_H
+#define SALIS_MEMORY_H
+
+void sm_init (sword order);
+void sm_quit (void);
+void sm_load (FILE *file);
+void sm_save (FILE *file);
+
+sbool sm_isInit (void);
+sword sm_getOrder (void);
+sword sm_getSize (void);
+sword sm_getMemBlockCount (void);
+sword sm_getAllocated (void);
+sword sm_getCap (void);
+
+sbool sm_isOverCap (void);
+sbool sm_isValidAt (sword addr);
+sbool sm_isMemBlockStartAt (sword addr);
+sbool sm_isAllocatedAt (sword addr);
+
+void sm_setMemBlockStartAt (sword addr);
+void sm_unsetMemBlockStartAt (sword addr);
+void sm_allocateAt (sword addr);
+void sm_freeAt (sword addr);
+sbyte sm_getInstAt (sword addr);
+void sm_setInstAt (sword addr, sbyte inst);
+sbyte sm_getByteAt (sword addr);
+void sm_setByteAt (sword addr, sbyte byte);
+
+#endif
diff --git a/include/process.h b/include/process.h new file mode 100644 index 0000000..35e1fdf --- /dev/null +++ b/include/process.h @@ -0,0 +1,40 @@ +#ifndef SALIS_PROCESS_H
+#define SALIS_PROCESS_H
+
+#define SPROC_REG_COUNT 4
+#define SPROC_STACK_SIZE 8
+#define SPROC_ELEM_COUNT (6 + SPROC_REG_COUNT + SPROC_STACK_SIZE)
+
+typedef struct {
+ sword mb1a;
+ sword mb1s;
+ sword mb2a;
+ sword mb2s;
+
+ sword ip;
+ sword sp;
+
+ sword regs [SPROC_REG_COUNT];
+ sword stack [SPROC_STACK_SIZE];
+} SProc;
+
+void sp_init (void);
+void sp_quit (void);
+void sp_load (FILE *file);
+void sp_save (FILE *file);
+
+sbool sp_isInit (void);
+sword sp_getCount (void);
+sword sp_getCap (void);
+sword sp_getFirst (void);
+sword sp_getLast (void);
+
+sbool sp_isFree (sword pidx);
+SProc sp_getProc (sword pidx);
+void sp_setProc (sword pidx, SProc proc);
+
+void sp_create (sword addr, sword size);
+void sp_kill (void);
+void sp_cycle (void);
+
+#endif
diff --git a/include/salis.h b/include/salis.h new file mode 100644 index 0000000..a9e2d3d --- /dev/null +++ b/include/salis.h @@ -0,0 +1,22 @@ +#ifndef SALIS_H
+#define SALIS_H
+
+#include <stdio.h>
+#include <types.h>
+#include <instset.h>
+#include <memory.h>
+#include <process.h>
+#include <evolver.h>
+
+void s_init (sword order);
+void s_quit (void);
+void s_load (const char *fileName);
+void s_save (const char *fileName);
+
+sbool s_isInit (void);
+sword s_getCycle (void);
+sword s_getEpoch (void);
+
+void s_cycle (void);
+
+#endif
diff --git a/include/types.h b/include/types.h new file mode 100644 index 0000000..3c0c3ff --- /dev/null +++ b/include/types.h @@ -0,0 +1,31 @@ +#ifndef SALIS_TYPES_H
+#define SALIS_TYPES_H
+
+#include <limits.h>
+
+#define SWORD_MAX (0xffffffff)
+#define SBYTE_MAX (0xff)
+
+#if USHRT_MAX == SWORD_MAX
+ typedef unsigned short sword;
+#elif UINT_MAX == SWORD_MAX
+ typedef unsigned int sword;
+#elif ULONG_MAX == SWORD_MAX
+ typedef unsigned long sword;
+#elif
+ #error "Cannot define 32 bit unsigned int (sword)"
+#endif
+
+#if UCHAR_MAX == SBYTE_MAX
+ typedef unsigned char sbyte;
+#elif
+ #error "Cannot define 8 bit unsigned int (sbyte)"
+#endif
+
+typedef int sbool;
+
+#define SFALSE (0)
+#define STRUE (1)
+#define SNULL ((sword)-1)
+
+#endif
|