#include "common.h"
-char opcodes_strings[N_INSTRUCTIONS][4] = {"nop", "inc", "dec", "lod", "ldl", "sav", "swp", "jmp", "jez", "hlt", "pts", "pfs", "dpx", "lor", "fdr"};
+char opcodes_strings[N_INSTRUCTIONS][4] = {"nop", "inc", "dec", "lod", "ldl", "sav", "swp", "jmp", "jez", "hlt", "pts", "pfs", "dpx", "lor", "fdr", "gri"};
-uint8_t opcode_kind[N_INSTRUCTIONS] = {0, 2, 2, 1, 1, 1, 1, 4, 1, 0, 5, 5, 3, 2, 0};
+uint8_t opcode_kind[N_INSTRUCTIONS] = {0, 2, 2, 1, 1, 1, 1, 4, 1, 0, 5, 5, 3, 2, 0, 5};
#pragma once
#include <stdint.h>
-#define N_INSTRUCTIONS 15
+#define N_INSTRUCTIONS 16
#define OPCODE_NOARGS 0
#define OPCODE_8_16 1
#include <string.h>
#include <stdint.h>
#include <unistd.h>
+#include <time.h>
#include "/home/bylex/software/tigr/tigr.h"
int main(int argc, char *argv[])
{
+ srand(time(NULL));
screen = tigrWindow(256,256, "Interpreter display", 0);
if(argc == 1)
{
+#include <stdlib.h>
+
#include "common.h"
#include "opcodes.h"
return;
}
-void (*opcodes[N_INSTRUCTIONS]) (uint8_t, uint8_t, uint8_t) = {nop, inc, dec, lod, ldl, sav, swp, jmp, jez, hlt, pts, pfs, dpx, lor, fdr};
+void gri(uint8_t dest_reg, uint8_t unused_2, uint8_t unused_3)
+{
+ regs[dest_reg] = rand();
+ current_instruction += 2;
+ return;
+}
+
+void (*opcodes[N_INSTRUCTIONS]) (uint8_t, uint8_t, uint8_t) = {nop, inc, dec, lod, ldl, sav, swp, jmp, jez, hlt, pts, pfs, dpx, lor, fdr, gri};
*
* lor, 3 byte length - instruction + dest register + register containing address where to load from
* fdr, 1 byte length - flush output to screen
+ * gri, 2 byte length - instruction + dest register - get random number from system
*
* all instructions are padded to 4 bytes
*/
extern void lor(uint8_t dest_reg, uint8_t unused_1, uint8_t mem_addr_reg);
extern void fdr(uint8_t unused_1, uint8_t unused_2, uint8_t unused_3);
+extern void gri(uint8_t dest_reg, uint8_t unused_2, uint8_t unused_3);
extern void (*opcodes[N_INSTRUCTIONS]) (uint8_t, uint8_t, uint8_t);
--- /dev/null
+ldl 0 65535
+; reg 0 is a screen pixel index
+ldl 2 1
+$LOOP
+gri 3
+gri 4
+; 3 now contains R and G, 4 contains B and A
+dpx 0 3 4
+dec 0 2
+jez 0 $END
+jmp $LOOP
+$END
+fdr
+hlt