run formatter
This commit is contained in:
parent
e679a3ce68
commit
f715709942
120
chip8.sv
120
chip8.sv
|
@ -15,30 +15,112 @@ module chip8 (
|
||||||
|
|
||||||
|
|
||||||
beeper beeper (sound_timer);
|
beeper beeper (sound_timer);
|
||||||
cpu cpu (memory, clk_in, keyboard, random_number, cycle_counter, program_counter, vram, sound_timer);
|
cpu cpu (
|
||||||
|
memory,
|
||||||
|
clk_in,
|
||||||
|
keyboard,
|
||||||
|
random_number,
|
||||||
|
cycle_counter,
|
||||||
|
program_counter,
|
||||||
|
vram,
|
||||||
|
sound_timer
|
||||||
|
);
|
||||||
gpu gpu (vram);
|
gpu gpu (vram);
|
||||||
keyboard kb (clk_in, keyboard);
|
keyboard kb (
|
||||||
rng randy (clk_in, program_counter, keyboard, cycle_counter, random_number);
|
clk_in,
|
||||||
|
keyboard
|
||||||
|
);
|
||||||
|
rng randy (
|
||||||
|
clk_in,
|
||||||
|
program_counter,
|
||||||
|
keyboard,
|
||||||
|
cycle_counter,
|
||||||
|
random_number
|
||||||
|
);
|
||||||
rom_loader loader (memory);
|
rom_loader loader (memory);
|
||||||
|
|
||||||
initial begin
|
initial begin
|
||||||
bit [7:0] fontset[79:0] = {
|
bit [7:0] fontset[79:0] = {
|
||||||
8'hF0, 8'h90, 8'h90, 8'h90, 8'hF0, // 0
|
8'hF0,
|
||||||
8'h20, 8'h60, 8'h20, 8'h20, 8'h70, // 1
|
8'h90,
|
||||||
8'hF0, 8'h10, 8'hF0, 8'h80, 8'hF0, // 2
|
8'h90,
|
||||||
8'hF0, 8'h10, 8'hF0, 8'h10, 8'hF0, // 3
|
8'h90,
|
||||||
8'h90, 8'h90, 8'hF0, 8'h10, 8'h10, // 4
|
8'hF0, // 0
|
||||||
8'hF0, 8'h80, 8'hF0, 8'h10, 8'hF0, // 5
|
8'h20,
|
||||||
8'hF0, 8'h80, 8'hF0, 8'h90, 8'hF0, // 6
|
8'h60,
|
||||||
8'hF0, 8'h10, 8'h20, 8'h40, 8'h40, // 7
|
8'h20,
|
||||||
8'hF0, 8'h90, 8'hF0, 8'h90, 8'hF0, // 8
|
8'h20,
|
||||||
8'hF0, 8'h90, 8'hF0, 8'h10, 8'hF0, // 9
|
8'h70, // 1
|
||||||
8'hF0, 8'h90, 8'hF0, 8'h90, 8'h90, // A
|
8'hF0,
|
||||||
8'hE0, 8'h90, 8'hE0, 8'h90, 8'hE0, // B
|
8'h10,
|
||||||
8'hF0, 8'h80, 8'h80, 8'h80, 8'hF0, // C
|
8'hF0,
|
||||||
8'hE0, 8'h90, 8'h90, 8'h90, 8'hE0, // D
|
8'h80,
|
||||||
8'hF0, 8'h80, 8'hF0, 8'h80, 8'hF0, // E
|
8'hF0, // 2
|
||||||
8'hF0, 8'h80, 8'hF0, 8'h80, 8'h80 // F
|
8'hF0,
|
||||||
|
8'h10,
|
||||||
|
8'hF0,
|
||||||
|
8'h10,
|
||||||
|
8'hF0, // 3
|
||||||
|
8'h90,
|
||||||
|
8'h90,
|
||||||
|
8'hF0,
|
||||||
|
8'h10,
|
||||||
|
8'h10, // 4
|
||||||
|
8'hF0,
|
||||||
|
8'h80,
|
||||||
|
8'hF0,
|
||||||
|
8'h10,
|
||||||
|
8'hF0, // 5
|
||||||
|
8'hF0,
|
||||||
|
8'h80,
|
||||||
|
8'hF0,
|
||||||
|
8'h90,
|
||||||
|
8'hF0, // 6
|
||||||
|
8'hF0,
|
||||||
|
8'h10,
|
||||||
|
8'h20,
|
||||||
|
8'h40,
|
||||||
|
8'h40, // 7
|
||||||
|
8'hF0,
|
||||||
|
8'h90,
|
||||||
|
8'hF0,
|
||||||
|
8'h90,
|
||||||
|
8'hF0, // 8
|
||||||
|
8'hF0,
|
||||||
|
8'h90,
|
||||||
|
8'hF0,
|
||||||
|
8'h10,
|
||||||
|
8'hF0, // 9
|
||||||
|
8'hF0,
|
||||||
|
8'h90,
|
||||||
|
8'hF0,
|
||||||
|
8'h90,
|
||||||
|
8'h90, // A
|
||||||
|
8'hE0,
|
||||||
|
8'h90,
|
||||||
|
8'hE0,
|
||||||
|
8'h90,
|
||||||
|
8'hE0, // B
|
||||||
|
8'hF0,
|
||||||
|
8'h80,
|
||||||
|
8'h80,
|
||||||
|
8'h80,
|
||||||
|
8'hF0, // C
|
||||||
|
8'hE0,
|
||||||
|
8'h90,
|
||||||
|
8'h90,
|
||||||
|
8'h90,
|
||||||
|
8'hE0, // D
|
||||||
|
8'hF0,
|
||||||
|
8'h80,
|
||||||
|
8'hF0,
|
||||||
|
8'h80,
|
||||||
|
8'hF0, // E
|
||||||
|
8'hF0,
|
||||||
|
8'h80,
|
||||||
|
8'hF0,
|
||||||
|
8'h80,
|
||||||
|
8'h80 // F
|
||||||
};
|
};
|
||||||
|
|
||||||
// Load fontset into memory
|
// Load fontset into memory
|
||||||
|
|
18
cpu.sv
18
cpu.sv
|
@ -48,10 +48,8 @@ module cpu(
|
||||||
$display("HW : PC %0d 0x%h", program_counter, program_counter);
|
$display("HW : PC %0d 0x%h", program_counter, program_counter);
|
||||||
|
|
||||||
if (cycle_counter % 20 == 0) begin
|
if (cycle_counter % 20 == 0) begin
|
||||||
if (delay_timer > 0)
|
if (delay_timer > 0) delay_timer--;
|
||||||
delay_timer--;
|
if (sound_timer > 0) sound_timer--;
|
||||||
if (sound_timer > 0)
|
|
||||||
sound_timer--;
|
|
||||||
end
|
end
|
||||||
|
|
||||||
casez (opcode)
|
casez (opcode)
|
||||||
|
@ -197,8 +195,7 @@ module cpu(
|
||||||
|
|
||||||
for (int r = 0; r < size; r++) begin
|
for (int r = 0; r < size; r++) begin
|
||||||
for (int c = 0; c < 8; c++) begin
|
for (int c = 0; c < 8; c++) begin
|
||||||
if (r + y_cord >= 32 || x_cord + c >= 64)
|
if (r + y_cord >= 32 || x_cord + c >= 64) continue;
|
||||||
continue;
|
|
||||||
screen_pixel = vram[((r+y_cord)*64)+(x_cord+c)];
|
screen_pixel = vram[((r+y_cord)*64)+(x_cord+c)];
|
||||||
sprite_pixel = memory[{16'h0000, index_reg}+r] & ('h80 >> c);
|
sprite_pixel = memory[{16'h0000, index_reg}+r] & ('h80 >> c);
|
||||||
|
|
||||||
|
@ -214,13 +211,15 @@ module cpu(
|
||||||
end
|
end
|
||||||
'hE?9E: begin
|
'hE?9E: begin
|
||||||
$display("HW : INSTR SKP Vx");
|
$display("HW : INSTR SKP Vx");
|
||||||
if (keyboard[{registers[(opcode & 'h0F00) >> 8]}[3:0]] == 1) begin
|
scratch_8 = registers[(opcode&'h0F00)>>8];
|
||||||
|
if (keyboard[scratch_8[3:0]] == 1) begin
|
||||||
program_counter += 2;
|
program_counter += 2;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
'hE?A1: begin
|
'hE?A1: begin
|
||||||
$display("HW : INSTR SNE Vx");
|
$display("HW : INSTR SNE Vx");
|
||||||
if (keyboard[{registers[(opcode & 'h0F00) >> 8]}[3:0]] != 1) begin
|
scratch_8 = registers[(opcode&'h0F00)>>8];
|
||||||
|
if (keyboard[scratch_8[3:0]] != 1) begin
|
||||||
program_counter += 2;
|
program_counter += 2;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -293,8 +292,7 @@ module cpu(
|
||||||
default: $display("HW : ILLEGAL INSTRUCTION");
|
default: $display("HW : ILLEGAL INSTRUCTION");
|
||||||
endcase
|
endcase
|
||||||
|
|
||||||
if (!halt)
|
if (!halt) program_counter += 2;
|
||||||
program_counter += 2;
|
|
||||||
|
|
||||||
cycle_counter++;
|
cycle_counter++;
|
||||||
end
|
end
|
||||||
|
|
6
makefile
6
makefile
|
@ -1,3 +1,5 @@
|
||||||
|
.PHONY: run clean format
|
||||||
|
|
||||||
SDL_CFLAGS = `sdl2-config --cflags`
|
SDL_CFLAGS = `sdl2-config --cflags`
|
||||||
SDL_LDFLAGS = `sdl2-config --libs`
|
SDL_LDFLAGS = `sdl2-config --libs`
|
||||||
|
|
||||||
|
@ -13,4 +15,8 @@ run: build
|
||||||
clean:
|
clean:
|
||||||
rm -rf obj_dir
|
rm -rf obj_dir
|
||||||
|
|
||||||
|
format:
|
||||||
|
verible-verilog-format *.sv --inplace && clang-format *.cpp -i
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,8 @@ module rom_loader (
|
||||||
|
|
||||||
initial begin
|
initial begin
|
||||||
int rom_size = load_rom();
|
int 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 (int i = 0; i < rom_size; i++) begin
|
for (int i = 0; i < rom_size; i++) begin
|
||||||
memory['h200+i] = get_next_instr();
|
memory['h200+i] = get_next_instr();
|
||||||
end
|
end
|
||||||
|
|
32
yayacemu.cpp
32
yayacemu.cpp
|
@ -1,14 +1,14 @@
|
||||||
#include "svdpi.h"
|
|
||||||
#include "Vchip8__Dpi.h"
|
|
||||||
#include <iostream>
|
|
||||||
#include <memory.h>
|
|
||||||
#include "Vchip8.h"
|
#include "Vchip8.h"
|
||||||
|
#include "Vchip8__Dpi.h"
|
||||||
|
#include "svdpi.h"
|
||||||
#include "verilated.h"
|
#include "verilated.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <SDL2/SDL_image.h>
|
#include <SDL2/SDL_image.h>
|
||||||
#include <SDL2/SDL_quit.h>
|
#include <SDL2/SDL_quit.h>
|
||||||
#include <SDL2/SDL_timer.h>
|
#include <SDL2/SDL_timer.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <memory.h>
|
||||||
|
|
||||||
#define SCREEN_WIDTH 64
|
#define SCREEN_WIDTH 64
|
||||||
#define SCREEN_HEIGHT 32
|
#define SCREEN_HEIGHT 32
|
||||||
|
@ -22,16 +22,15 @@ char* rom_name;
|
||||||
|
|
||||||
void init_screen() {
|
void init_screen() {
|
||||||
SDL_Init(SDL_INIT_EVERYTHING);
|
SDL_Init(SDL_INIT_EVERYTHING);
|
||||||
window =
|
window = SDL_CreateWindow(
|
||||||
SDL_CreateWindow("Yet Another Yet Another Chip-8 Emulator", // creates a window
|
"Yet Another Yet Another Chip-8 Emulator", // creates a window
|
||||||
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH * 10,
|
||||||
SCREEN_WIDTH * 10, SCREEN_HEIGHT * 10, 0);
|
SCREEN_HEIGHT * 10, 0);
|
||||||
renderer =
|
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
||||||
SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
|
||||||
|
|
||||||
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888,
|
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888,
|
||||||
SDL_TEXTUREACCESS_STREAMING,
|
SDL_TEXTUREACCESS_STREAMING, SCREEN_WIDTH,
|
||||||
SCREEN_WIDTH, SCREEN_HEIGHT);
|
SCREEN_HEIGHT);
|
||||||
std::cout << "INF_EMU: Screen initialized" << '\n';
|
std::cout << "INF_EMU: Screen initialized" << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,13 +71,9 @@ int load_rom() {
|
||||||
return rom_size;
|
return rom_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
svBitVecVal get_next_instr() {
|
svBitVecVal get_next_instr() { return (uint8_t)fgetc(rom_file); }
|
||||||
return (uint8_t) fgetc(rom_file);
|
|
||||||
}
|
|
||||||
|
|
||||||
void close_rom() {
|
void close_rom() { fclose(rom_file); }
|
||||||
fclose(rom_file);
|
|
||||||
}
|
|
||||||
|
|
||||||
svBitVecVal get_key() {
|
svBitVecVal get_key() {
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
|
@ -126,7 +121,6 @@ svBitVecVal get_key() {
|
||||||
return 255;
|
return 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return 255;
|
return 255;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue