remove init blocks from core componsnts
This commit is contained in:
		
							parent
							
								
									f395551009
								
							
						
					
					
						commit
						f949c2515b
					
				
					 3 changed files with 109 additions and 104 deletions
				
			
		
							
								
								
									
										186
									
								
								chip8.sv
									
										
									
									
									
								
							
							
						
						
									
										186
									
								
								chip8.sv
									
										
									
									
									
								
							|  | @ -1,5 +1,6 @@ | ||||||
| module chip8 ( | module chip8 ( | ||||||
|     input wire clk_in |     input wire clk_in, | ||||||
|  |     input wire rst_in | ||||||
| ); | ); | ||||||
| 
 | 
 | ||||||
|   bit [31:0] vram[0:2047]; |   bit [31:0] vram[0:2047]; | ||||||
|  | @ -16,6 +17,7 @@ module chip8 ( | ||||||
| 
 | 
 | ||||||
|   beeper beeper (sound_timer); |   beeper beeper (sound_timer); | ||||||
|   cpu cpu ( |   cpu cpu ( | ||||||
|  |       rst_in, | ||||||
|       memory, |       memory, | ||||||
|       clk_in, |       clk_in, | ||||||
|       keyboard, |       keyboard, | ||||||
|  | @ -39,98 +41,100 @@ module chip8 ( | ||||||
|   ); |   ); | ||||||
|   rom_loader loader (memory); |   rom_loader loader (memory); | ||||||
| 
 | 
 | ||||||
|   initial begin |   always_ff @(posedge clk_in) begin | ||||||
|     bit [7:0] fontset[79:0] = { |     if (rst_in) begin | ||||||
|       8'hF0, |         bit [7:0] fontset[79:0] = { | ||||||
|       8'h90, |           8'hF0, | ||||||
|       8'h90, |           8'h90, | ||||||
|       8'h90, |           8'h90, | ||||||
|       8'hF0,  // 0
 |           8'h90, | ||||||
|       8'h20, |           8'hF0,  // 0
 | ||||||
|       8'h60, |           8'h20, | ||||||
|       8'h20, |           8'h60, | ||||||
|       8'h20, |           8'h20, | ||||||
|       8'h70,  // 1
 |           8'h20, | ||||||
|       8'hF0, |           8'h70,  // 1
 | ||||||
|       8'h10, |           8'hF0, | ||||||
|       8'hF0, |           8'h10, | ||||||
|       8'h80, |           8'hF0, | ||||||
|       8'hF0,  // 2
 |           8'h80, | ||||||
|       8'hF0, |           8'hF0,  // 2
 | ||||||
|       8'h10, |           8'hF0, | ||||||
|       8'hF0, |           8'h10, | ||||||
|       8'h10, |           8'hF0, | ||||||
|       8'hF0,  // 3
 |           8'h10, | ||||||
|       8'h90, |           8'hF0,  // 3
 | ||||||
|       8'h90, |           8'h90, | ||||||
|       8'hF0, |           8'h90, | ||||||
|       8'h10, |           8'hF0, | ||||||
|       8'h10,  // 4
 |           8'h10, | ||||||
|       8'hF0, |           8'h10,  // 4
 | ||||||
|       8'h80, |           8'hF0, | ||||||
|       8'hF0, |           8'h80, | ||||||
|       8'h10, |           8'hF0, | ||||||
|       8'hF0,  // 5
 |           8'h10, | ||||||
|       8'hF0, |           8'hF0,  // 5
 | ||||||
|       8'h80, |           8'hF0, | ||||||
|       8'hF0, |           8'h80, | ||||||
|       8'h90, |           8'hF0, | ||||||
|       8'hF0,  // 6
 |           8'h90, | ||||||
|       8'hF0, |           8'hF0,  // 6
 | ||||||
|       8'h10, |           8'hF0, | ||||||
|       8'h20, |           8'h10, | ||||||
|       8'h40, |           8'h20, | ||||||
|       8'h40,  // 7
 |           8'h40, | ||||||
|       8'hF0, |           8'h40,  // 7
 | ||||||
|       8'h90, |           8'hF0, | ||||||
|       8'hF0, |           8'h90, | ||||||
|       8'h90, |           8'hF0, | ||||||
|       8'hF0,  // 8
 |           8'h90, | ||||||
|       8'hF0, |           8'hF0,  // 8
 | ||||||
|       8'h90, |           8'hF0, | ||||||
|       8'hF0, |           8'h90, | ||||||
|       8'h10, |           8'hF0, | ||||||
|       8'hF0,  // 9
 |           8'h10, | ||||||
|       8'hF0, |           8'hF0,  // 9
 | ||||||
|       8'h90, |           8'hF0, | ||||||
|       8'hF0, |           8'h90, | ||||||
|       8'h90, |           8'hF0, | ||||||
|       8'h90,  // A
 |           8'h90, | ||||||
|       8'hE0, |           8'h90,  // A
 | ||||||
|       8'h90, |           8'hE0, | ||||||
|       8'hE0, |           8'h90, | ||||||
|       8'h90, |           8'hE0, | ||||||
|       8'hE0,  // B
 |           8'h90, | ||||||
|       8'hF0, |           8'hE0,  // B
 | ||||||
|       8'h80, |           8'hF0, | ||||||
|       8'h80, |           8'h80, | ||||||
|       8'h80, |           8'h80, | ||||||
|       8'hF0,  // C
 |           8'h80, | ||||||
|       8'hE0, |           8'hF0,  // C
 | ||||||
|       8'h90, |           8'hE0, | ||||||
|       8'h90, |           8'h90, | ||||||
|       8'h90, |           8'h90, | ||||||
|       8'hE0,  // D
 |           8'h90, | ||||||
|       8'hF0, |           8'hE0,  // D
 | ||||||
|       8'h80, |           8'hF0, | ||||||
|       8'hF0, |           8'h80, | ||||||
|       8'h80, |           8'hF0, | ||||||
|       8'hF0,  // E
 |           8'h80, | ||||||
|       8'hF0, |           8'hF0,  // E
 | ||||||
|       8'h80, |           8'hF0, | ||||||
|       8'hF0, |           8'h80, | ||||||
|       8'h80, |           8'hF0, | ||||||
|       8'h80  // F
 |           8'h80, | ||||||
|     }; |           8'h80  // F
 | ||||||
|  |         }; | ||||||
|      |      | ||||||
|     // Load fontset into memory
 |         // Load fontset into memory
 | ||||||
|     for (int i = 0; i < 80; i++) begin |         for (int i = 0; i < 80; i++) begin | ||||||
|       memory[i] = fontset[79-i]; |           memory[i] = fontset[79-i]; | ||||||
|     end |         end | ||||||
|      |      | ||||||
|     // Initialize keyboard bits
 |         // Initialize keyboard bits
 | ||||||
|     for (int i = 0; i < 15; i++) begin |         for (int i = 0; i < 15; i++) begin | ||||||
|       keyboard[i] = 0; |           keyboard[i] = 0; | ||||||
|  |         end | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
| endmodule | endmodule | ||||||
|  |  | ||||||
							
								
								
									
										21
									
								
								cpu.sv
									
										
									
									
									
								
							
							
						
						
									
										21
									
								
								cpu.sv
									
										
									
									
									
								
							|  | @ -1,4 +1,5 @@ | ||||||
| module cpu ( | module cpu ( | ||||||
|  |     input wire rst_in, | ||||||
|     output bit [7:0] memory[0:4095], |     output bit [7:0] memory[0:4095], | ||||||
|     input wire clk_in, |     input wire clk_in, | ||||||
|     input wire keyboard[15:0], |     input wire keyboard[15:0], | ||||||
|  | @ -31,18 +32,16 @@ module cpu ( | ||||||
|   logic [31:0] screen_pixel; |   logic [31:0] screen_pixel; | ||||||
|   logic [7:0] sprite_pixel; |   logic [7:0] sprite_pixel; | ||||||
| 
 | 
 | ||||||
|   // Initialize CPU
 |  | ||||||
|   initial begin |  | ||||||
|     halt = 0; |  | ||||||
|     watch_key = 255; |  | ||||||
|     sound_timer = 0; |  | ||||||
|     delay_timer = 0; |  | ||||||
|     cycle_counter = 0; |  | ||||||
|     program_counter = 'h200; |  | ||||||
|     stack_pointer = 4'b0000; |  | ||||||
|   end |  | ||||||
| 
 |  | ||||||
|   always_ff @(posedge clk_in) begin |   always_ff @(posedge clk_in) begin | ||||||
|  |     if (rst_in) begin | ||||||
|  |         halt = 0; | ||||||
|  |         watch_key = 255; | ||||||
|  |         sound_timer = 0; | ||||||
|  |         delay_timer = 0; | ||||||
|  |         cycle_counter = 0; | ||||||
|  |         program_counter = 'h200; | ||||||
|  |         stack_pointer = 4'b0000; | ||||||
|  |     end | ||||||
|     opcode = {memory[program_counter+0], memory[program_counter+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 0x%h", program_counter, program_counter); |     $display("HW     : PC %0d 0x%h", program_counter, program_counter); | ||||||
|  |  | ||||||
|  | @ -141,9 +141,11 @@ int main(int argc, char **argv) { | ||||||
| 
 | 
 | ||||||
|   Vchip8 *dut = new Vchip8{contextp}; |   Vchip8 *dut = new Vchip8{contextp}; | ||||||
| 
 | 
 | ||||||
|  |   dut->rst_in = 1; | ||||||
|   while (true) { |   while (true) { | ||||||
|     dut->clk_in ^= 1; |     dut->clk_in ^= 1; | ||||||
|     dut->eval(); |     dut->eval(); | ||||||
|  |     dut->rst_in = 0; | ||||||
|     usleep(1000000 / EMULATION_HZ); |     usleep(1000000 / EMULATION_HZ); | ||||||
|     if (SDL_QuitRequested()) { |     if (SDL_QuitRequested()) { | ||||||
|       std::cout << "INF_EMU: Received Quit from SDL. Goodbye!" << '\n'; |       std::cout << "INF_EMU: Received Quit from SDL. Goodbye!" << '\n'; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue