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)
}
while(fgets(line_buffer, 5, input_file))
{
+ if(current_addr > 65534) break;
memcpy(&(mem[current_addr]), line_buffer, 4);
current_addr = current_addr + 2;
}
tigrUpdate(screen);
printf("Press any key to exit...");
getc(stdin);
-
+
}
-/*
+/*
* 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
*/
}
-// 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;