Skip to content

Commit 189ac06

Browse files
committed
1.1.0: Added embedded assembler and support for .asm
1 parent f5ef3ba commit 189ac06

File tree

12 files changed

+426
-42
lines changed

12 files changed

+426
-42
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ WININCLUDES = -I libs/SDL2/include -I C:/C++ -I libs
55
WINCFLAGS = -L libs/SDL2/lib -lSDL2main -lSDL2 -lSDL2_image -L libs/jsoncpp/build-shared -ljsoncpp
66
DEBUGFLAGS = -c src/*.cpp -std=c++14 -m64 -g -I include
77
RELEASEFLAGS = -c src/*.cpp -std=c++14 -m64 -O3 -I include
8-
VERSION = 1.0.4
8+
VERSION = 1.1.0
99
NAME = risc-sim
1010

1111
default:

README.txt

Lines changed: 51 additions & 9 deletions
Large diffs are not rendered by default.

example_binaries/rsh.asm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
START: LDWI R0 0008
2+
RSH
3+
HLT

github-updater.risc-sim.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
{
2-
"latest": "1.0.4",
2+
"latest": "1.1.0",
33
"keep": [
44
"binaries/",
55
"settings/"
66
],
77
"releases": [
8+
{
9+
"tag": "1.1.0",
10+
"linux": "risc-sim-1.1.0-linux-x64.tar.gz",
11+
"win": "risc-sim-1.1.0-windows-x64.zip"
12+
},
813
{
914
"tag": "1.0.4",
1015
"linux": "risc-sim-1.0.4-linux-x64.tar.gz",

include/math.hpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ namespace math {
137137
string StatusRegisterToHexstr(StatusRegister sr);
138138
/**
139139
* @brief Function to get the hex string from the Control Bus
140-
* @param sr The Control Bus
140+
* @param cb The Control Bus
141141
* @return The hex string
142142
*/
143143
string ControlBusToHexstr(ControlBus cb);
@@ -147,4 +147,23 @@ namespace math {
147147
* @returns The twos complement
148148
*/
149149
Uint16 twosComplement(Uint16 n);
150+
/**
151+
* @brief Function to get the register from an argument
152+
* @param arg The argument
153+
* @returns The register
154+
*/
155+
string argumentToRegister(string arg);
156+
/**
157+
* @brief Function to transform a word into little endian
158+
* @param w The word
159+
* @returns The little endian string
160+
*/
161+
vector<string> wordToLittleEndian(string w);
162+
/**
163+
* @brief Function to see if a string is contained in a string vector
164+
* @param v The string vector
165+
* @param s The string
166+
* @returns True if found
167+
*/
168+
bool vectorContains(vector<string> v, string s);
150169
}

include/risc.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,10 @@ class CentralMemory {
446446
void reset(Uint32 psize);
447447
/**
448448
* @brief Program to load the program
449+
* @param interpreterSettings The interpreter settings, type IterpreterSettings
450+
* @param logger The logger, type Logger
449451
*/
450-
void loadProgram(string path, bool bin, Logger* logger);
452+
void loadProgram(InterpreterSettings* settings, Logger* logger);
451453
/**
452454
* @brief Function that reads the system bus and operate
453455
*/

include/utils.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct WindowSettings {
7676
struct InterpreterSettings {
7777
string file;
7878
Uint32 ramSize, start;
79-
bool binary;
79+
Uint8 type;
8080
};
8181
/**
8282
* @brief Structure to contain binary interpreter settings

settings/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"interpreter": {
3-
"file": "binary.hex",
3+
"file": "rsh.asm",
44
"ram_size": 100,
55
"start": 0
66
},

src/main.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,19 @@ int main(int argc, char* args[]) {
3333
bool fullInstruction = false, constantFullInstruction = false, progressBarAll = false;
3434
Uint8 key; //For keyboard input
3535

36+
//Capturing cout in log file
37+
if(settings.console.log) freopen("log.txt", "w", stdout);
38+
logger.setColors(settings.console);
39+
3640
//Interpreter
3741
SystemBus SB;
3842
CentralMemory CM(&SB, settings.interpreter.ramSize);
3943
InputOutputDevices IOD(&SB);
4044
CentralProcessingUnit CPU(&SB, &CM, &IOD, settings.interpreter);
41-
CM.loadProgram(settings.interpreter.file, settings.interpreter.binary, &logger);
45+
CM.loadProgram(&settings.interpreter, &logger);
46+
CPU.reset(settings.interpreter);
4247
IOD.input(0x0);
4348

44-
//Capturing cout in log file
45-
if(settings.console.log) freopen("log.txt", "w", stdout);
46-
logger.setColors(settings.console);
47-
4849
//SDL and IMG initialization
4950
cout << logger.getStringTime();
5051
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) > 0) {
@@ -63,7 +64,7 @@ int main(int argc, char* args[]) {
6364
//Printing the settings
6465
cout << logger.getStringTime() << logger.info << "Settings:" << endl << settings << logger.reset << endl;
6566
//Render the window
66-
RenderWindow window("RISC-CPU SIMULATOR v1.0.4", settings.win.width, settings.win.height,
67+
RenderWindow window("RISC-CPU SIMULATOR v1.1.0", settings.win.width, settings.win.height,
6768
flags, &logger, &settings, "res/icon-64.png");
6869
SDL_ShowCursor(0);
6970

@@ -390,11 +391,11 @@ int main(int argc, char* args[]) {
390391
refresh = true;
391392
constantFullInstruction = false;
392393
settings = JsonManager::getSettings();
393-
CPU.reset(settings.interpreter);
394394
SB = SystemBus();
395395
CM.reset(settings.interpreter.ramSize);
396396
IOD.reset();
397-
CM.loadProgram(settings.interpreter.file, settings.interpreter.binary, &logger);
397+
CM.loadProgram(&settings.interpreter, &logger);
398+
CPU.reset(settings.interpreter);
398399
msStep = 1000 / settings.win.maxFps;
399400
}
400401
}

src/math.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,24 @@ string math::ControlBusToHexstr(ControlBus cb) {
159159
s[2] = (cb.W ? 'W' : 'B');
160160
s[3] = '\0';
161161
return s;
162+
}
163+
164+
string math::argumentToRegister(string arg) {
165+
if(arg.length() != 2 || arg[0] != 'R') throw(1);
166+
return arg.substr(1, 1);
167+
}
168+
169+
vector<string> math::wordToLittleEndian(string w) {
170+
if(w.length() != 4) throw(2);
171+
vector<string> v;
172+
v.push_back(w.substr(2, 2));
173+
v.push_back(w.substr(0, 2));
174+
return v;
175+
}
176+
177+
bool math::vectorContains(vector<string> v, string s) {
178+
for(string e : v) {
179+
if(e == s) return true;
180+
}
181+
return false;
162182
}

0 commit comments

Comments
 (0)