1
0
Fork 0
mirror of https://github.com/pnx/m16vm synced 2026-06-16 03:44:55 +02:00

vm/cpu.c: use the error() function from error.h

This commit is contained in:
Henrik Hautakoski 2019-07-31 11:30:48 +02:00
parent 5477a8be63
commit 54c7a35b8f
No known key found for this signature in database
GPG key ID: 96765B12FEAC4745

View file

@ -26,6 +26,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#include "error.h"
#include "cpu.h" #include "cpu.h"
#include "mm.h" #include "mm.h"
#include "syscall.h" #include "syscall.h"
@ -83,7 +84,7 @@ static void execute(struct cpu_state *state, struct instr *instr) {
vm_syscall(instr->i.rs, instr->i.imm, state->reg); vm_syscall(instr->i.rs, instr->i.imm, state->reg);
break; break;
default : default :
fprintf(stderr, "Invalid instruction (%.2X)\n", instr->opcode); error("Invalid instruction (%.2X)", instr->opcode);
state->pc = state->instr_cnt; state->pc = state->instr_cnt;
break; break;
} }
@ -101,8 +102,7 @@ void cpu_init(struct cpu_state *state)
int cpu_instr_load(struct cpu_state *state, void *ptr, unsigned len) { int cpu_instr_load(struct cpu_state *state, void *ptr, unsigned len) {
if (len % 2) { if (len % 2) {
fprintf(stderr, "Error: Instruction length must be a multiple of 2\n"); return error("Instruction length must be a multiple of 2");
return -1;
} }
state->instr_mem = ptr; state->instr_mem = ptr;
@ -119,7 +119,7 @@ void cpu_instr_unload(struct cpu_state *state) {
void cpu_set_pc(struct cpu_state *state, uint16_t addr) { void cpu_set_pc(struct cpu_state *state, uint16_t addr) {
if (addr > state->instr_cnt / 2) if (addr > state->instr_cnt / 2)
fprintf(stderr, "Runtime error: Invalid instruction address %ui\n", addr); error("Invalid instruction address %ui", addr);
state->pc = addr; state->pc = addr;
} }