From: bylex Date: Thu, 20 Feb 2025 14:41:27 +0000 (+0100) Subject: improve docs, add dpx X-Git-Url: https://git.bylex.cz/?a=commitdiff_plain;h=35a385f3ec1ef66d69593c1c35e5d685384359e9;p=maturita.git improve docs, add dpx --- diff --git a/interpreter.c b/interpreter.c index fd16481..cb83f35 100644 --- a/interpreter.c +++ b/interpreter.c @@ -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); - + } diff --git a/opcodes.c b/opcodes.c index 42211a9..50f40fe 100644 --- 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 @@ -14,22 +14,22 @@ * * 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;