improve docs, add dpx
authorbylex <mbilek06@gmail.com>
Thu, 20 Feb 2025 14:41:27 +0000 (15:41 +0100)
committerbylex <mbilek06@gmail.com>
Thu, 20 Feb 2025 14:41:27 +0000 (15:41 +0100)
interpreter.c
opcodes.c

index fd16481920ec3b550dab4460c6f570b225d60fee..cb83f35889148f6390a1da46cb1ca0a679ce5a0d 100644 (file)
@@ -25,7 +25,7 @@ uint64_t instruction_counter = 0;
 
 void load_mem(char* file_name)
 {
-       uint16_t current_addr = 0;
+       uint32_t current_addr = 0;
        uint8_t* line_buffer = malloc(5);
        FILE* input_file = fopen(file_name, "rb");
        if(!input_file)
@@ -35,6 +35,7 @@ void load_mem(char* file_name)
        }
        while(fgets(line_buffer, 5, input_file))
        {
+        if(current_addr > 65534) break;
                memcpy(&(mem[current_addr]), line_buffer, 4);
                current_addr = current_addr + 2;
        }
@@ -77,5 +78,5 @@ int main(int argc, char *argv[])
        tigrUpdate(screen);
        printf("Press any key to exit...");
        getc(stdin);
-       
+
 }
index 42211a9c6b7afe88d13fdca04f839808394ae6ff..50f40fe9f57e3df26c4f4ee18ac152b2737619a1 100644 (file)
--- a/opcodes.c
+++ b/opcodes.c
@@ -1,12 +1,12 @@
-/* 
+/*
  * operation codes with description
  * register size is 2 bytes
  *
  * nop, 1 byte length - instruction - no operation
- * 
+ *
  * inc, 3 byte length - instruction + dest register + source register - increment dest register by source register
  * dec, 3 byte length - instruction + dest register + source register - decrement dest register by source register
- * 
+ *
  * lod, 4 byte length - instruction + dest register + source address - load 2 bytes from memory to register
  * ldl, 4 byte length - instruction + dest register + number literal - load 2 bytes from instruction to register
  * sav, 4 byte length - instruction + dest register + source address - save 2 bytes from register to 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
  *
  * pts, 2 byte length - instruction + source register - puts a value on the stack
  * pfs, 2 byte length - instruction + dest register - pulls a value from the stack
- * stack is 256 values long, 16 bit values 
- * 
- * TODO: figure out input/output 
- * 
+ * stack is 256 values long, 16 bit values
+ *
+ * TODO: figure out input/output
+ *
  * 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) 
+ * 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)
  *
  * lor, 3 byte length - instruction + dest register + register containing address where to load from
- * 
+ *
  * all instructions are padded to 4 bytes
  */
 
@@ -75,7 +75,7 @@ void dec(uint8_t dest_reg, uint8_t unused_1, uint8_t source_reg)
 }
 
 
-// loads addressed byte and the next byte into register 
+// loads addressed byte and the next byte into register
 void lod(uint8_t dest_reg, uint8_t source_addr_1, uint8_t source_addr_2)
 {
        uint16_t source_addr = (uint16_t)source_addr_1 << 8 | source_addr_2;