rng module
This commit is contained in:
parent
3a37bc7d68
commit
6ef29f55e7
10
chip8.sv
10
chip8.sv
|
@ -35,6 +35,15 @@ logic debug_overlay;
|
||||||
rd_memory_data
|
rd_memory_data
|
||||||
);
|
);
|
||||||
|
|
||||||
|
logic [7:0] random_byte;
|
||||||
|
rng randy(
|
||||||
|
slow_clk,
|
||||||
|
{wr_memory_data, rd_memory_data},
|
||||||
|
keymap,
|
||||||
|
cycle_counter,
|
||||||
|
random_byte
|
||||||
|
);
|
||||||
|
|
||||||
logic [15:0] keymap;
|
logic [15:0] keymap;
|
||||||
|
|
||||||
keypad keypad (
|
keypad keypad (
|
||||||
|
@ -58,6 +67,7 @@ logic debug_overlay;
|
||||||
fpga_clk,
|
fpga_clk,
|
||||||
rd_memory_data,
|
rd_memory_data,
|
||||||
keymap,
|
keymap,
|
||||||
|
random_byte,
|
||||||
cycle_counter,
|
cycle_counter,
|
||||||
rd_memory_address,
|
rd_memory_address,
|
||||||
wr_memory_address,
|
wr_memory_address,
|
||||||
|
|
20
cpu.sv
20
cpu.sv
|
@ -5,6 +5,7 @@ module cpu (
|
||||||
input wire fpga_clk,
|
input wire fpga_clk,
|
||||||
input wire [7:0] rd_memory_data,
|
input wire [7:0] rd_memory_data,
|
||||||
input wire [15:0] keymap,
|
input wire [15:0] keymap,
|
||||||
|
input wire [7:0] random_byte,
|
||||||
output int cycle_counter,
|
output int cycle_counter,
|
||||||
output logic [11:0] rd_memory_address,
|
output logic [11:0] rd_memory_address,
|
||||||
output logic [11:0] wr_memory_address,
|
output logic [11:0] wr_memory_address,
|
||||||
|
@ -109,7 +110,7 @@ logic [5:0] lcd_led;
|
||||||
typedef enum {INIT, DRAW} draw_stage;
|
typedef enum {INIT, DRAW} draw_stage;
|
||||||
|
|
||||||
typedef enum {CLS, LD, DRW, JP, ALU, CALU, CALL, RET, ALUJ, LDL, BCD, IOJ, IOW, NIOJ} cpu_opcode;
|
typedef enum {CLS, LD, DRW, JP, ALU, CALU, CALL, RET, ALUJ, LDL, BCD, IOJ, IOW, NIOJ} cpu_opcode;
|
||||||
typedef enum {REG, IDX_REG, BYTE, MEM, SPRITE_MEM, KEY, DELAY_TIMER, SOUND_TIMER} data_type;
|
typedef enum {REG, IDX_REG, BYTE, MEM, SPRITE_MEM, KEY, DELAY_TIMER, SOUND_TIMER, RAND} data_type;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
draw_stage stage;
|
draw_stage stage;
|
||||||
|
@ -161,7 +162,6 @@ logic [5:0] lcd_led;
|
||||||
end
|
end
|
||||||
|
|
||||||
always_ff @(posedge clk_in) begin
|
always_ff @(posedge clk_in) begin
|
||||||
$display("%0d", sound_timer);
|
|
||||||
if (cycle_counter % 200 == 0) begin
|
if (cycle_counter % 200 == 0) begin
|
||||||
vblank <= 0;
|
vblank <= 0;
|
||||||
if (delay_timer > 0)
|
if (delay_timer > 0)
|
||||||
|
@ -423,6 +423,17 @@ logic [5:0] lcd_led;
|
||||||
compute_of <= 0;
|
compute_of <= 0;
|
||||||
state <= ST_EXEC;
|
state <= ST_EXEC;
|
||||||
end
|
end
|
||||||
|
16'hC???: begin
|
||||||
|
instr.op <= LD;
|
||||||
|
|
||||||
|
instr.src <= RAND;
|
||||||
|
instr.src_byte <= {4'h0, opcode[7:0]};
|
||||||
|
|
||||||
|
instr.dst <= REG;
|
||||||
|
instr.dst_reg <= opcode[11:8];
|
||||||
|
|
||||||
|
state <= ST_EXEC;
|
||||||
|
end
|
||||||
16'hD???: begin
|
16'hD???: begin
|
||||||
instr.op <= DRW;
|
instr.op <= DRW;
|
||||||
|
|
||||||
|
@ -641,7 +652,10 @@ logic [5:0] lcd_led;
|
||||||
end else if (instr.src == DELAY_TIMER) begin
|
end else if (instr.src == DELAY_TIMER) begin
|
||||||
instr.src_byte <= { 4'h0, delay_timer };
|
instr.src_byte <= { 4'h0, delay_timer };
|
||||||
instr.src <= BYTE;
|
instr.src <= BYTE;
|
||||||
end
|
end else if (instr.src == RAND) begin
|
||||||
|
instr.src_byte <= {4'h0, random_byte} & instr.src_byte ;
|
||||||
|
instr.src <= BYTE;
|
||||||
|
end
|
||||||
end
|
end
|
||||||
LDL: begin
|
LDL: begin
|
||||||
if (instr.dst == REG) begin
|
if (instr.dst == REG) begin
|
||||||
|
|
2
makefile
2
makefile
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
SDL_CFLAGS = `sdl2-config --cflags`
|
SDL_CFLAGS = `sdl2-config --cflags`
|
||||||
SDL_LDFLAGS = `sdl2-config --libs`
|
SDL_LDFLAGS = `sdl2-config --libs`
|
||||||
SV_FILES=aastructs.sv cpu.sv chip8.sv gpu.sv alu.sv keypad.sv
|
SV_FILES=aastructs.sv cpu.sv chip8.sv gpu.sv alu.sv keypad.sv rng.sv
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
verilator --lint-only -DDUMMY_GPU --timing ${SV_FILES}
|
verilator --lint-only -DDUMMY_GPU --timing ${SV_FILES}
|
||||||
|
|
22
yayacemu.cpp
22
yayacemu.cpp
|
@ -18,6 +18,9 @@ SDL_Window *window;
|
||||||
SDL_Renderer *renderer;
|
SDL_Renderer *renderer;
|
||||||
SDL_Texture *texture;
|
SDL_Texture *texture;
|
||||||
|
|
||||||
|
int keys[16];
|
||||||
|
bool is_beeping;
|
||||||
|
|
||||||
void init_screen() {
|
void init_screen() {
|
||||||
SDL_Init(SDL_INIT_EVERYTHING);
|
SDL_Init(SDL_INIT_EVERYTHING);
|
||||||
window = SDL_CreateWindow(
|
window = SDL_CreateWindow(
|
||||||
|
@ -30,7 +33,7 @@ void init_screen() {
|
||||||
SDL_TEXTUREACCESS_STREAMING, SCREEN_WIDTH,
|
SDL_TEXTUREACCESS_STREAMING, SCREEN_WIDTH,
|
||||||
SCREEN_HEIGHT);
|
SCREEN_HEIGHT);
|
||||||
}
|
}
|
||||||
bool is_beeping;
|
|
||||||
void draw_screen(const svLogicVecVal *vram) {
|
void draw_screen(const svLogicVecVal *vram) {
|
||||||
uint32_t *screen = (uint32_t *)malloc(SCREEN_WIDTH * SCREEN_HEIGHT * 32);
|
uint32_t *screen = (uint32_t *)malloc(SCREEN_WIDTH * SCREEN_HEIGHT * 32);
|
||||||
for (int i = 0; i < 1024; i++) {
|
for (int i = 0; i < 1024; i++) {
|
||||||
|
@ -45,21 +48,12 @@ void draw_screen(const svLogicVecVal *vram) {
|
||||||
SDL_RenderCopy(renderer, texture, NULL, NULL);
|
SDL_RenderCopy(renderer, texture, NULL, NULL);
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
free(screen);
|
free(screen);
|
||||||
// std::cout << "INF_EMU: Drawing Frame" << '\n';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1 2 3 A
|
|
||||||
// 4 5 6 B
|
|
||||||
// 7 8 9 C
|
|
||||||
// * 0 # D
|
|
||||||
//
|
|
||||||
int keys[16];
|
|
||||||
uint8_t get_key(uint8_t col) {
|
uint8_t get_key(uint8_t col) {
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
uint8_t res = 0xFF;
|
uint8_t res = 0xFF;
|
||||||
|
|
||||||
// col 1000 - r1
|
|
||||||
|
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
uint8_t down = 0;
|
uint8_t down = 0;
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
|
@ -178,10 +172,12 @@ uint8_t get_key(uint8_t col) {
|
||||||
if (col == 0b1011)
|
if (col == 0b1011)
|
||||||
res = res & 0b0111;
|
res = res & 0b0111;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keys[12] == 1) {
|
if (keys[12] == 1) {
|
||||||
if (col == 0b0111)
|
if (col == 0b0111)
|
||||||
res = res & 0b1110;
|
res = res & 0b1110;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keys[13] == 1) {
|
if (keys[13] == 1) {
|
||||||
if (col == 0b0111)
|
if (col == 0b0111)
|
||||||
res = res & 0b1101;
|
res = res & 0b1101;
|
||||||
|
@ -191,13 +187,12 @@ uint8_t get_key(uint8_t col) {
|
||||||
if (col == 0b0111)
|
if (col == 0b0111)
|
||||||
res = res & 0b1011;
|
res = res & 0b1011;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keys[15] == 1) {
|
if (keys[15] == 1) {
|
||||||
if (col == 0b0111)
|
if (col == 0b0111)
|
||||||
res = res & 0b0111;
|
res = res & 0b0111;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (res != 0)
|
|
||||||
// printf("%04b %04b\n", res, col);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,11 +209,10 @@ int main(int argc, char **argv) {
|
||||||
dut->fpga_clk ^= 1;
|
dut->fpga_clk ^= 1;
|
||||||
dut->eval();
|
dut->eval();
|
||||||
|
|
||||||
|
|
||||||
is_beeping = dut->beep == 1;
|
is_beeping = dut->beep == 1;
|
||||||
|
|
||||||
if (SDL_QuitRequested()) {
|
if (SDL_QuitRequested()) {
|
||||||
std::cout << "INF_EMU: Received Quit from SDL. Goodbye!" << '\n';
|
std::cout << "Goodbye!" << '\n';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue