corax+
This commit is contained in:
parent
1c16da9ed9
commit
55f965625f
|
@ -45,3 +45,4 @@ yayacemu [PATH_TO_YOUR_ROM]
|
||||||
|
|
||||||
![Chip 8 Logo Demo](https://github.com/nickorlow/yayacemu/blob/main/screenshots/chip8-logo.png?raw=true)
|
![Chip 8 Logo Demo](https://github.com/nickorlow/yayacemu/blob/main/screenshots/chip8-logo.png?raw=true)
|
||||||
![IBM Logo Demo](https://github.com/nickorlow/yayacemu/blob/main/screenshots/ibm-logo.png?raw=true)
|
![IBM Logo Demo](https://github.com/nickorlow/yayacemu/blob/main/screenshots/ibm-logo.png?raw=true)
|
||||||
|
![CORAX+ Test Demo](https://github.com/nickorlow/yayacemu/blob/main/screenshots/corax.png?raw=true)
|
||||||
|
|
|
@ -14,10 +14,11 @@ module rom_loader (
|
||||||
rom_size = load_rom();
|
rom_size = load_rom();
|
||||||
$display("HW : ROM size is %0d bytes (%0d bits) (%0d instructions)", rom_size, rom_size * 8, rom_size / 2);
|
$display("HW : ROM size is %0d bytes (%0d bits) (%0d instructions)", rom_size, rom_size * 8, rom_size / 2);
|
||||||
for (i = 0; i < rom_size; i++) begin
|
for (i = 0; i < rom_size; i++) begin
|
||||||
memory[i] = get_next_instr();
|
memory['h200 + i] = get_next_instr();
|
||||||
end
|
end
|
||||||
close_rom();
|
close_rom();
|
||||||
$display("HW : ROM loaded successfully");
|
$display("HW : ROM loaded successfully");
|
||||||
|
$finish;
|
||||||
rom_ready = 1;
|
rom_ready = 1;
|
||||||
end
|
end
|
||||||
endmodule
|
endmodule
|
||||||
|
|
BIN
screenshots/corax.png
Normal file
BIN
screenshots/corax.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.9 KiB |
BIN
tests/3-corax+.ch8
Normal file
BIN
tests/3-corax+.ch8
Normal file
Binary file not shown.
|
@ -89,16 +89,14 @@ int main(int argc, char** argv) {
|
||||||
contextp->commandArgs(argc, argv);
|
contextp->commandArgs(argc, argv);
|
||||||
Vyayacemu* top = new Vyayacemu{contextp};
|
Vyayacemu* top = new Vyayacemu{contextp};
|
||||||
//while (!contextp->gotFinish()) {
|
//while (!contextp->gotFinish()) {
|
||||||
top->pc_out = 0;
|
for (int i = 0; i < 20000; i++) {
|
||||||
while (top->pc_out < 100) {
|
|
||||||
top->clk_in ^= 1;
|
top->clk_in ^= 1;
|
||||||
top->pc_in = top->pc_out;
|
|
||||||
top->eval();
|
top->eval();
|
||||||
usleep(500);
|
usleep(500);
|
||||||
}
|
}
|
||||||
printf("TB : Testbench has reached end of simulation. Pausing for 10 seconds before exiting");
|
printf("TB : Testbench has reached end of simulation. Pausing for 10 seconds before exiting");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
usleep(10000000);
|
usleep(3000000);
|
||||||
delete top;
|
delete top;
|
||||||
delete contextp;
|
delete contextp;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
155
yayacemu.sv
155
yayacemu.sv
|
@ -1,39 +1,44 @@
|
||||||
module yayacemu (
|
module yayacemu (
|
||||||
input wire clk_in,
|
input wire clk_in
|
||||||
input int pc_in,
|
|
||||||
output int pc_out
|
|
||||||
);
|
);
|
||||||
import "DPI-C" function void init_screen();
|
import "DPI-C" function void init_screen();
|
||||||
|
|
||||||
wire [31:0] vram [0:2047];
|
wire [31:0] vram [0:2047];
|
||||||
bit [7:0] memory [0:4095];
|
bit [7:0] memory [0:4095];
|
||||||
wire [7:0] registers [0:15];
|
wire [7:0] registers [0:15];
|
||||||
logic [7:0] index_reg;
|
logic [3:0] stack_pointer;
|
||||||
|
wire [15:0] stack [0:15];
|
||||||
|
|
||||||
|
logic [15:0] index_reg;
|
||||||
logic rom_ready;
|
logic rom_ready;
|
||||||
int pc;
|
logic [15:0] program_counter;
|
||||||
|
|
||||||
rom_loader rl (memory, rom_ready);
|
rom_loader rl (memory, rom_ready);
|
||||||
chip8_cpu cpu (memory, clk_in, vram, index_reg, registers, pc_in, pc_out);
|
chip8_cpu cpu (memory, clk_in, vram, stack, index_reg, stack_pointer, registers, program_counter);
|
||||||
chip8_gpu gpu (vram);
|
chip8_gpu gpu (vram);
|
||||||
|
|
||||||
initial begin
|
initial begin
|
||||||
|
program_counter = 'h200;
|
||||||
|
stack_pointer = 4'b0000;
|
||||||
init_screen();
|
init_screen();
|
||||||
end
|
end
|
||||||
|
|
||||||
endmodule
|
endmodule
|
||||||
|
|
||||||
module chip8_cpu(
|
module chip8_cpu(
|
||||||
input bit [7:0] memory [0:4095],
|
output bit [7:0] memory [0:4095],
|
||||||
input wire clk_in,
|
input wire clk_in,
|
||||||
output wire [31:0] vram [0:2047],
|
output wire [31:0] vram [0:2047],
|
||||||
output wire [7:0] index_reg,
|
output wire [15:0] stack [0:15],
|
||||||
|
output wire [15:0] index_reg,
|
||||||
|
output wire [3:0] stack_pointer,
|
||||||
output wire [7:0] registers [0:15],
|
output wire [7:0] registers [0:15],
|
||||||
input int pc_in,
|
output wire [15:0] program_counter
|
||||||
output int pc_out
|
|
||||||
);
|
);
|
||||||
|
|
||||||
logic [15:0] opcode;
|
logic [15:0] opcode;
|
||||||
logic [15:0] scratch;
|
logic [15:0] scratch;
|
||||||
|
logic [15:0] scratch2;
|
||||||
|
|
||||||
logic [31:0] x_cord;
|
logic [31:0] x_cord;
|
||||||
logic [31:0] y_cord;
|
logic [31:0] y_cord;
|
||||||
|
@ -42,13 +47,14 @@ module chip8_cpu(
|
||||||
logic [7:0] sprite_pixel;
|
logic [7:0] sprite_pixel;
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
logic [7:0] i8;
|
||||||
|
|
||||||
int r;
|
int r;
|
||||||
int c;
|
int c;
|
||||||
always_ff @(posedge clk_in) begin
|
always_ff @(posedge clk_in) begin
|
||||||
opcode = {memory[pc_in], memory[pc_in+1]};
|
opcode = {memory[program_counter+0], memory[program_counter+1]};
|
||||||
$display("HW : opcode is 0x%h (%b)", opcode, opcode);
|
$display("HW : opcode is 0x%h (%b)", opcode, opcode);
|
||||||
$display("HW : PC %0d", pc_in);
|
$display("HW : PC %0d 0x%h", program_counter, program_counter);
|
||||||
|
|
||||||
casez(opcode)
|
casez(opcode)
|
||||||
'h00E0: begin
|
'h00E0: begin
|
||||||
|
@ -57,10 +63,42 @@ module chip8_cpu(
|
||||||
vram[i] = 0;
|
vram[i] = 0;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
'h00EE: $display("HW : INSTR RET");
|
'h00EE: begin
|
||||||
'h0???: $display("HW : INSTR SYS addr");
|
$display("HW : INSTR RET");
|
||||||
'h1???: $display("HW : INSTR JP addr");
|
stack_pointer--;
|
||||||
'h2???: $display("HW : INSTR CALL addr");
|
program_counter = stack[stack_pointer];
|
||||||
|
end
|
||||||
|
'h0???: $display("HW : INSTR SYS addr (Treating as NOP)");
|
||||||
|
'h1???: begin
|
||||||
|
$display("HW : INSTR JP addr");
|
||||||
|
program_counter = (opcode & 'h0FFF) - 2;
|
||||||
|
end
|
||||||
|
'h2???: begin
|
||||||
|
$display("HW : INSTR CALL addr");
|
||||||
|
stack[stack_pointer] = program_counter;
|
||||||
|
stack_pointer++;
|
||||||
|
program_counter = (opcode & 'h0FFF) - 2;
|
||||||
|
end
|
||||||
|
'h3???: begin
|
||||||
|
$display("HW : INSTR SE Vx, byte");
|
||||||
|
scratch = (opcode & 'h00FF);
|
||||||
|
if (scratch[7:0] == registers[(opcode & 'h0F00) >> 8]) begin
|
||||||
|
program_counter += 2;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
'h4???: begin
|
||||||
|
$display("HW : INSTR SNE Vx, byte");
|
||||||
|
scratch = (opcode & 'h00FF);
|
||||||
|
if (scratch[7:0] != registers[(opcode & 'h0F00) >> 8]) begin
|
||||||
|
program_counter += 2;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
'h5??0: begin
|
||||||
|
$display("HW : INSTR SE Vx, Vy");
|
||||||
|
if (registers[(opcode & 'h00F0) >> 4] == registers[(opcode & 'h0F00) >> 8]) begin
|
||||||
|
program_counter += 2;
|
||||||
|
end
|
||||||
|
end
|
||||||
'h6???: begin
|
'h6???: begin
|
||||||
$display("HW : INSTR LD Vx, byte");
|
$display("HW : INSTR LD Vx, byte");
|
||||||
scratch = (opcode & 'h00FF);
|
scratch = (opcode & 'h00FF);
|
||||||
|
@ -71,37 +109,110 @@ module chip8_cpu(
|
||||||
scratch = (opcode & 'h00FF);
|
scratch = (opcode & 'h00FF);
|
||||||
registers[(opcode & 'h0F00) >> 8] += scratch[7:0];
|
registers[(opcode & 'h0F00) >> 8] += scratch[7:0];
|
||||||
end
|
end
|
||||||
|
'h8??0: begin
|
||||||
|
$display("HW : INSTR LD Vx, Vy");
|
||||||
|
registers[(opcode & 'h0F00) >> 8] = registers[(opcode & 'h00F0) >> 4];
|
||||||
|
end
|
||||||
|
'h8??1: begin
|
||||||
|
$display("HW : INSTR OR Vx, Vy");
|
||||||
|
registers[(opcode & 'h0F00) >> 8] |= registers[(opcode & 'h00F0) >> 4];
|
||||||
|
end
|
||||||
|
'h8??2: begin
|
||||||
|
$display("HW : INSTR AND Vx, Vy");
|
||||||
|
registers[(opcode & 'h0F00) >> 8] &= registers[(opcode & 'h00F0) >> 4];
|
||||||
|
end
|
||||||
|
'h8??3: begin
|
||||||
|
$display("HW : INSTR XOR Vx, Vy");
|
||||||
|
registers[(opcode & 'h0F00) >> 8] ^= registers[(opcode & 'h00F0) >> 4];
|
||||||
|
end
|
||||||
|
'h8??4: begin
|
||||||
|
$display("HW : INSTR ADD Vx, Vy");
|
||||||
|
registers[(opcode & 'h0F00) >> 8] += registers[(opcode & 'h00F0) >> 4];
|
||||||
|
end
|
||||||
|
'h8??5: begin
|
||||||
|
$display("HW : INSTR SUB Vx, Vy");
|
||||||
|
registers[(opcode & 'h0F00) >> 8] -= registers[(opcode & 'h00F0) >> 4];
|
||||||
|
end
|
||||||
|
'h8??6: begin
|
||||||
|
$display("HW : INSTR SHR Vx {, Vy}");
|
||||||
|
registers[(opcode & 'h0F00) >> 8] = registers[(opcode & 'h00F0) >> 4]>> 1;
|
||||||
|
end
|
||||||
|
'h8??7: begin
|
||||||
|
$display("HW : INSTR SUBN Vx, Vy");
|
||||||
|
registers[(opcode & 'h0F00) >> 8] = registers[(opcode & 'h00F0) >> 4] - registers[(opcode & 'h0F00) >> 8];
|
||||||
|
end
|
||||||
|
'h8??E: begin
|
||||||
|
$display("HW : INSTR SHL Vx {, Vy}");
|
||||||
|
registers[(opcode & 'h0F00) >> 8] = registers[(opcode & 'h00F0) >> 4]<< 1;
|
||||||
|
end
|
||||||
'hA???: begin
|
'hA???: begin
|
||||||
$display("HW : INSTR LD I, addr");
|
$display("HW : INSTR LD I, addr");
|
||||||
scratch = (opcode & 'h0FFF);
|
index_reg = (opcode & 'h0FFF);
|
||||||
index_reg = scratch[7:0];
|
|
||||||
end
|
end
|
||||||
'hD???: begin
|
'hD???: begin
|
||||||
$display("HW : INSTR DRW Vx, Vy, nibble");
|
$display("HW : INSTR DRW Vx, Vy, nibble");
|
||||||
x_cord = {24'h000000, registers[(opcode & 'h0F00) >> 8]};
|
x_cord = {24'h000000, registers[(opcode & 'h0F00) >> 8]};
|
||||||
y_cord = {24'h000000, registers[(opcode & 'h00F0) >> 4]};
|
y_cord = {24'h000000, registers[(opcode & 'h00F0) >> 4]};
|
||||||
|
|
||||||
|
x_cord %= 64;
|
||||||
|
y_cord %= 32;
|
||||||
|
|
||||||
scratch = (opcode & 'h000F);
|
scratch = (opcode & 'h000F);
|
||||||
size = scratch[7:0];
|
size = scratch[7:0];
|
||||||
|
registers[15] = 0;
|
||||||
|
|
||||||
for (r = 0; r < size; r++) begin
|
for (r = 0; r < size; r++) begin
|
||||||
for ( c = 0; c < 8; c++) begin
|
for ( c = 0; c < 8; c++) begin
|
||||||
screen_pixel = vram[((r + y_cord) * 64) + (x_cord + c)];
|
screen_pixel = vram[((r + y_cord) * 64) + (x_cord + c)];
|
||||||
sprite_pixel = memory[{24'h000000, index_reg} + r] & ('h80 >> c);
|
sprite_pixel = memory[{16'h0000, index_reg} + r] & ('h80 >> c);
|
||||||
|
|
||||||
if (|sprite_pixel) begin
|
if (|sprite_pixel) begin
|
||||||
if (screen_pixel == 32'hFFFFFFFF) begin
|
if (screen_pixel == 32'hFFFFFFFF) begin
|
||||||
registers[15] = 1;
|
registers[15] = 1;
|
||||||
end
|
end
|
||||||
vram[((r + y_cord) * 64) + (x_cord + c)] = screen_pixel ^ 32'hFFFFFFFF;
|
vram[((r + y_cord) * 64) + (x_cord + c)] ^= 32'hFFFFFFFF;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
'hF?33: begin
|
||||||
|
$display("HW : INSTR LD B, Vx");
|
||||||
|
scratch = {8'h00, registers[(opcode & 'h0F00) >> 8]};
|
||||||
|
scratch2 = scratch % 10;
|
||||||
|
memory[index_reg + 2] = scratch2[7:0];
|
||||||
|
scratch /= 10;
|
||||||
|
scratch2 = scratch % 10;
|
||||||
|
memory[index_reg + 1] = scratch2[7:0];
|
||||||
|
scratch /= 10;
|
||||||
|
scratch2 = scratch % 10;
|
||||||
|
memory[index_reg + 0] = scratch2[7:0];
|
||||||
|
end
|
||||||
|
'hF?55: begin
|
||||||
|
$display("HW : INSTR LD [I], Vx");
|
||||||
|
scratch = (opcode & 'h0F00) >> 8;
|
||||||
|
for (i8 = 0; i8 <= scratch[7:0]; i8++) begin
|
||||||
|
scratch2 = index_reg + {8'h00, i8};
|
||||||
|
memory[scratch2[11:0]] = registers[i8[3:0]];
|
||||||
|
end
|
||||||
|
index_reg++;
|
||||||
|
end
|
||||||
|
'hF?65: begin
|
||||||
|
$display("HW : INSTR LD Vx, [I]");
|
||||||
|
scratch = (opcode & 'h0F00) >> 8;
|
||||||
|
for (i8 = 0; i8 <= scratch[7:0]; i8++) begin
|
||||||
|
scratch2 = index_reg + {8'h00, i8};
|
||||||
|
registers[i8[3:0]] = memory[scratch2[11:0]];
|
||||||
|
end
|
||||||
|
index_reg++;
|
||||||
|
end
|
||||||
|
'hF?1E: begin
|
||||||
|
$display("HW : INSTR ADD I, Vx");
|
||||||
|
index_reg = index_reg + {8'h00, registers[(opcode & 'h0F00) >> 8]};
|
||||||
|
end
|
||||||
default: $display("HW : ILLEGAL INSTRUCTION");
|
default: $display("HW : ILLEGAL INSTRUCTION");
|
||||||
endcase
|
endcase
|
||||||
|
|
||||||
pc_out <= pc_in + 2;
|
program_counter += 2;
|
||||||
end
|
end
|
||||||
endmodule
|
endmodule
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue