run formatter

This commit is contained in:
Nicholas Orlowsky 2024-01-31 21:04:52 -06:00
parent e679a3ce68
commit f715709942
9 changed files with 550 additions and 469 deletions

120
chip8.sv
View file

@ -15,30 +15,112 @@ module chip8 (
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);
keyboard kb (clk_in, keyboard);
rng randy (clk_in, program_counter, keyboard, cycle_counter, random_number);
keyboard kb (
clk_in,
keyboard
);
rng randy (
clk_in,
program_counter,
keyboard,
cycle_counter,
random_number
);
rom_loader loader (memory);
initial begin
bit [7:0] fontset[79:0] = {
8'hF0, 8'h90, 8'h90, 8'h90, 8'hF0, // 0
8'h20, 8'h60, 8'h20, 8'h20, 8'h70, // 1
8'hF0, 8'h10, 8'hF0, 8'h80, 8'hF0, // 2
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
8'hF0,
8'h90,
8'h90,
8'h90,
8'hF0, // 0
8'h20,
8'h60,
8'h20,
8'h20,
8'h70, // 1
8'hF0,
8'h10,
8'hF0,
8'h80,
8'hF0, // 2
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

18
cpu.sv
View file

@ -48,10 +48,8 @@ module cpu(
$display("HW : PC %0d 0x%h", program_counter, program_counter);
if (cycle_counter % 20 == 0) begin
if (delay_timer > 0)
delay_timer--;
if (sound_timer > 0)
sound_timer--;
if (delay_timer > 0) delay_timer--;
if (sound_timer > 0) sound_timer--;
end
casez (opcode)
@ -197,8 +195,7 @@ module cpu(
for (int r = 0; r < size; r++) begin
for (int c = 0; c < 8; c++) begin
if (r + y_cord >= 32 || x_cord + c >= 64)
continue;
if (r + y_cord >= 32 || x_cord + c >= 64) continue;
screen_pixel = vram[((r+y_cord)*64)+(x_cord+c)];
sprite_pixel = memory[{16'h0000, index_reg}+r] & ('h80 >> c);
@ -214,13 +211,15 @@ module cpu(
end
'hE?9E: begin
$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;
end
end
'hE?A1: begin
$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;
end
end
@ -293,8 +292,7 @@ module cpu(
default: $display("HW : ILLEGAL INSTRUCTION");
endcase
if (!halt)
program_counter += 2;
if (!halt) program_counter += 2;
cycle_counter++;
end

View file

@ -1,3 +1,5 @@
.PHONY: run clean format
SDL_CFLAGS = `sdl2-config --cflags`
SDL_LDFLAGS = `sdl2-config --libs`
@ -13,4 +15,8 @@ run: build
clean:
rm -rf obj_dir
format:
verible-verilog-format *.sv --inplace && clang-format *.cpp -i

View file

@ -8,7 +8,8 @@ module rom_loader (
initial begin
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
memory['h200+i] = get_next_instr();
end

View file

@ -1,14 +1,14 @@
#include "svdpi.h"
#include "Vchip8__Dpi.h"
#include <iostream>
#include <memory.h>
#include "Vchip8.h"
#include "Vchip8__Dpi.h"
#include "svdpi.h"
#include "verilated.h"
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_quit.h>
#include <SDL2/SDL_timer.h>
#include <inttypes.h>
#include <iostream>
#include <memory.h>
#define SCREEN_WIDTH 64
#define SCREEN_HEIGHT 32
@ -22,16 +22,15 @@ char* rom_name;
void init_screen() {
SDL_Init(SDL_INIT_EVERYTHING);
window =
SDL_CreateWindow("Yet Another Yet Another Chip-8 Emulator", // creates a window
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
SCREEN_WIDTH * 10, SCREEN_HEIGHT * 10, 0);
renderer =
SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
window = SDL_CreateWindow(
"Yet Another Yet Another Chip-8 Emulator", // creates a window
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH * 10,
SCREEN_HEIGHT * 10, 0);
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888,
SDL_TEXTUREACCESS_STREAMING,
SCREEN_WIDTH, SCREEN_HEIGHT);
SDL_TEXTUREACCESS_STREAMING, SCREEN_WIDTH,
SCREEN_HEIGHT);
std::cout << "INF_EMU: Screen initialized" << '\n';
}
@ -72,13 +71,9 @@ int load_rom() {
return rom_size;
}
svBitVecVal get_next_instr() {
return (uint8_t) fgetc(rom_file);
}
svBitVecVal get_next_instr() { return (uint8_t)fgetc(rom_file); }
void close_rom() {
fclose(rom_file);
}
void close_rom() { fclose(rom_file); }
svBitVecVal get_key() {
SDL_Event event;
@ -126,7 +121,6 @@ svBitVecVal get_key() {
return 255;
}
default:
return 255;
}