Adding previous work.
This commit is contained in:
		
							parent
							
								
									25c4ea796f
								
							
						
					
					
						commit
						3109cc0e75
					
				
					 3 changed files with 57 additions and 0 deletions
				
			
		
							
								
								
									
										2
									
								
								.gitignore
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,2 @@ | |||
| .vscode/ | ||||
| bin/ | ||||
							
								
								
									
										42
									
								
								cpu.hpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								cpu.hpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,42 @@ | |||
| #include <iostream> | ||||
| #include <cstdint> | ||||
| 
 | ||||
| namespace plutoisa | ||||
| { | ||||
|     using namespace std; | ||||
| 
 | ||||
|     uint8_t *registers = (uint8_t *)malloc(8 * sizeof(uint8_t)); | ||||
|     uint8_t *memory = (uint8_t *)malloc(128 * sizeof(uint8_t)); | ||||
|     uint8_t *pointer = (uint8_t *)malloc(sizeof(uint8_t)); | ||||
| 
 | ||||
|     void cpuInstructions(uint8_t *rom) | ||||
|     { | ||||
|         switch (rom[*pointer]) | ||||
|         { | ||||
|         case 0x00: // LOAD R0 M0
 | ||||
|             registers[rom[*pointer + 1]] = memory[rom[*pointer + 2]]; | ||||
|             *pointer += 3; | ||||
|             break; | ||||
|         case 0x01: // STORE R0 M0
 | ||||
|             memory[rom[*pointer + 2]] = registers[rom[*pointer + 1]]; | ||||
|             *pointer += 3; | ||||
|             break; | ||||
|         default: | ||||
|             cout << "Invalid Instruction, expect broken behavior" << endl; | ||||
|             exit(1); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     void cpuEmulation(uint8_t *rom) | ||||
|     { | ||||
|         *pointer = 0; | ||||
| 
 | ||||
|         memory[0] = 0x12; | ||||
| 
 | ||||
|         while (true) | ||||
|         { | ||||
|             cout << static_cast<int>(registers[0]) << endl; | ||||
|             cpuInstructions(rom); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										13
									
								
								main.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								main.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,13 @@ | |||
| #include "cpu.hpp" | ||||
| 
 | ||||
| using namespace plutoisa; | ||||
| 
 | ||||
| int main() | ||||
| { | ||||
|     uint8_t *rom = (uint8_t *)malloc(16 * sizeof(uint8_t)); | ||||
|     rom[0] = 0x00; | ||||
|     rom[1] = 0x00; | ||||
|     rom[2] = 0x00; | ||||
|     rom[3] = 0xFF; | ||||
|     cpuEmulation(rom); | ||||
| } | ||||
		Reference in a new issue