Skip to content
14 changes: 14 additions & 0 deletions ls8/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ void alu(struct cpu *cpu, enum alu_op op, unsigned char regA, unsigned char regB
}
}

unsigned char read_ram(struct cpu *cpu, unsigned char address)
{
return cpu->ram[address];
}

//set value at address in ram to new value
void ram_write(struct cpu *cpu, unsigned char address, unsigned char value)
{
cpu->ram[address] = value;
}

/**
* Run the CPU
*/
Expand All @@ -64,4 +75,7 @@ void cpu_run(struct cpu *cpu)
void cpu_init(struct cpu *cpu)
{
// TODO: Initialize the PC and other special registers
cpu->pc = 0;
memset(cpu->reg, 0, sizeof(unsigned char)*8); //just use size of cpu reg?
memset(cpu->ram, 0, sizeof(unsigned char)*256);
}
7 changes: 5 additions & 2 deletions ls8/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
#define _CPU_H_

// Holds all information about the CPU
struct cpu {
typedef struct cpu {
// TODO
// PC
unsigned char pc;
// registers (array)
unsigned char reg[8];
// ram (array)
};
unsigned char ram[256]
} cpu;

// ALU operations
enum alu_op {
Expand Down