CFLAGS = -g -w -O0
all: int ass
-
int:
- $(CC) $(CFLAGS) interpreter.c -o interpreter
+ $(CC) -I$(HOME)/software/tigr $(HOME)/software/tigr/tigr.c interpreter.c -o interpreter -lGLU -lGL -lX11 $(CFLAGS)
ass:
$(CC) $(CFLAGS) assembler.c -o assembler
clean:
case 0:
// current token is instruction code
uint8_t i = 0;
- while(i < N_INSTRUCTIONS - 1)
+ while(i < N_INSTRUCTIONS)
{
int token_len = strlen(token);
if(token_len != 3)
break;
case 1:
// current token is first parameter
- inst.params[0] = (uint8_t)atoi(token);
+ // jump only has an address
+ if(inst.instruction_code == 7)
+ {
+ if(token[0] == '$')
+ {
+ int i = 0;
+ int token_len = strlen(token);
+ while(i < token_len)
+ {
+ if(isspace(token[i]))
+ {
+ token[i] = '\0';
+ }
+ i++;
+ }
+
+ int j = 0;
+ bool label_known = false;
+ while(j < labels_index)
+ {
+ if(strcmp(labels[j].label_name, token) == 0)
+ {
+ inst.params[1] = (uint8_t)(labels[j].addr >> 8);
+ inst.params[2] = (uint8_t)(labels[j].addr);
+ label_known = true;
+ break;
+ }
+ j++;
+ }
+ if(!label_known)
+ {
+ fprintf(stderr, "Unknown identifier\n");
+ exit(1);
+ }
+ break;
+ }
+ else
+ {
+ uint16_t token_int = atoi(token);
+ inst.params[1] = (uint8_t)(token_int >> 8);
+ inst.params[2] = (uint8_t)(token_int);
+ }
+ }
+ else
+ {
+ inst.params[0] = (uint8_t)atoi(token);
+ }
break;
case 2:
// current token is second parameter
}
else
{
- uint16_t token_int = atoi(token);
- inst.params[1] = (uint8_t)(token_int >> 8);
- inst.params[2] = (uint8_t)(token_int);
+ if(inst.instruction_code == 12)
+ {
+ uint8_t token_int = atoi(token);
+ inst.params[1] = (uint8_t)(token_int);
+ }
+ else
+ {
+ uint16_t token_int = atoi(token);
+ inst.params[1] = (uint8_t)(token_int >> 8);
+ inst.params[2] = (uint8_t)(token_int);
+ }
break;
}
break;
case 3:
// current token is third parameter
+ uint8_t token_int = atoi(token);
+ inst.params[2] = token_int;
break;
}
token_count++;
#include "common.h"
-char opcodes_strings[N_INSTRUCTIONS][4] = {"nop", "inc", "dec", "lod", "ldl", "sav", "swp", "jmp", "jez", "hlt", "pts", "pfs"};
+char opcodes_strings[N_INSTRUCTIONS][4] = {"nop", "inc", "dec", "lod", "ldl", "sav", "swp", "jmp", "jez", "hlt", "pts", "pfs", "dpx"};
-#define N_INSTRUCTIONS 12
+#define N_INSTRUCTIONS 13
#include <string.h>
#include <stdint.h>
-#include "opcodes.h"
+#include "tigr.h"
+
+#include "opcodes.c"
uint16_t regs[256];
uint16_t mem[65536];
uint16_t stack[256];
uint8_t stack_pointer;
+Tigr* screen;
+
uint16_t current_instruction = 0; // entry location
bool halted = false;
uint8_t halted_reason = 0;
int main(int argc, char *argv[])
{
+ screen = tigrWindow(256,256, "Interpreter display", 0);
if(argc == 1)
{
fprintf(stderr, "No memory file!\n");
fflush(stdout);
(*opcodes[instruction]) (arg1, arg2, arg3);
instruction_counter++;
+ if(instruction_counter % 1024 == 0)
+ {
+ tigrUpdate(screen);
+ }
}
printf("\nExecution halted: cause %d\n", halted_reason);
* sav, 4 byte length - instruction + dest register + source address - save 2 bytes from register to memory
* swp, 4 byte length - instruction + register + address - swap 2 bytes between register and memory
*
- * jmp, 2 byte length - instruction + register - jump to address in memory
+ * jmp, 2 byte length - instruction + unused + address - jump to address contained in register in memory
* jez, 4 byte length - instruction + cond register + address - conditional jump to address in memory, if untrue acts as nop
*
* hlt, 1 byte length - instruction - halts execution
*
* wex, 2 byte length - instruction + source register - write 2 bytes to external output(stdout)
* rex, 2 byte length - instruction + dest register - read from external(stdin) - blocks execution until 2 bytes are read
+ *
+ * dpx, 4 byte length - instruction + register with pixel location + register with R and G + register with B and A(R and B are first 8 bits, G and A are second 8 bits)
*
* all instructions are padded to 4 bytes
*/
#include "common.h"
+#include "tigr.h"
+
extern uint16_t regs[256];
extern uint16_t mem[65536];
extern bool halted; // is the execution halted?
extern uint8_t halted_reason;
+extern Tigr* screen;
+
void nop(uint8_t unused_1, uint8_t unused_2, uint8_t unused_3)
{
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};
+void dpx(uint8_t pixel_num_reg, uint8_t red_green_reg, uint8_t blue_alpha_reg)
+{
+// tigrPlot(screen, (uint8_t)(regs[pixel_num_reg]), (uint8_t)(regs[pixel_num_reg] >> 8), tigrRGBA((uint8_t)(regs[red_green_reg] >> 8), (uint8_t)regs[red_green_reg], (uint8_t)(regs[blue_alpha_reg] >> 8), (uint8_t)regs[blue_alpha_reg]));
+ screen->pix[regs[pixel_num_reg]] = tigrRGBA((uint8_t)(regs[red_green_reg] >> 8), (uint8_t)regs[red_green_reg], (uint8_t)(regs[blue_alpha_reg] >> 8), (uint8_t)regs[blue_alpha_reg]);
+ 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};