Skip to content

Commit 50c28bb

Browse files
committed
1.1.2: Modified TSTO and fixed a minor bug about memory loading
1 parent 2a8b0e9 commit 50c28bb

File tree

6 files changed

+46
-30
lines changed

6 files changed

+46
-30
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.1.1
8+
VERSION = 1.1.2
99
NAME = risc-sim
1010

1111
default:

README.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
║ │ + TSTI: to test if an input operation has been completed (Z = 1) or not (Z = 0) │ ║
137137
║ │ - assembly: TSTI hhhh │ ║
138138
║ │ - binary: 1000010000000000 hexadecimal: 8400 status register: Z:D, N:-, C:-, V:- │ ║
139-
║ │ + TSTO: to test if an output operation has been completed (Z = 1, monitor is always ready) │ ║
139+
║ │ + TSTO: to test if an output operation has been completed (Z = 1) or not (Z = 0) │ ║
140140
║ │ - assembly: TSTO hhhh │ ║
141141
║ │ - binary: 1000010100000000 hexadecimal: 8500 status register: Z:D, N:-, C:-, V:- │ ║
142142
║ │ ! WARNING: I/O instructions have to be followed by the address (x16) of the I/O device │ ║

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.1.1",
2+
"latest": "1.1.2",
33
"keep": [
44
"binaries/",
55
"settings/"
66
],
77
"releases": [
8+
{
9+
"tag": "1.1.2",
10+
"linux": "risc-sim-1.1.2-linux-x64.tar.gz",
11+
"win": "risc-sim-1.1.2-windows-x64.zip"
12+
},
813
{
914
"tag": "1.1.1",
1015
"linux": "risc-sim-1.1.1-linux-x64.tar.gz",

include/risc.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,8 @@ class CentralProcessingUnit{
227227
* @param pSB System bus pointer
228228
* @param pCM Central memory pointer
229229
* @param pIOD Input/output devices pointer
230-
* @param settings The interpreter settings
231230
*/
232-
CentralProcessingUnit(SystemBus* pSB, CentralMemory* pCM, InputOutputDevices* pIOD, InterpreterSettings settings);
231+
CentralProcessingUnit(SystemBus* pSB, CentralMemory* pCM, InputOutputDevices* pIOD);
233232
/**
234233
* @brief Function to reset the CPU
235234
* @param settings The interpreter settings
@@ -444,9 +443,8 @@ class CentralMemory {
444443
/**
445444
* @brief Contructor
446445
* @param pSB System bus pointer
447-
* @param psize Memory fixed size
448446
*/
449-
CentralMemory(SystemBus* pSB, Uint32 psize);
447+
CentralMemory(SystemBus* pSB);
450448
/**
451449
* @brief Function to reset the CM
452450
* @param psize Memory fixed size
@@ -507,9 +505,14 @@ class InputOutputDevices {
507505
* @returns True if a key byte was sent, false if 0x00 or nothing was sent
508506
*/
509507
bool getSent();
508+
/**
509+
* @brief Function to see if a byte was received from the monitor
510+
* @returns True if a byte was received, false otherwise
511+
*/
512+
bool getReceived();
510513
private:
511514
SystemBus* SB; //System Bus pointer
512515
Uint8 key;
513516
string line0, line1, line2, line3;
514-
bool sent;
517+
bool sent, received;
515518
};

src/main.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ int main(int argc, char* args[]) {
4040

4141
//Interpreter
4242
SystemBus SB;
43-
CentralMemory CM(&SB, settings.interpreter.ramSize);
43+
CentralMemory CM(&SB);
4444
InputOutputDevices IOD(&SB);
45-
CentralProcessingUnit CPU(&SB, &CM, &IOD, settings.interpreter);
45+
CentralProcessingUnit CPU(&SB, &CM, &IOD);
4646
CM.loadProgram(&settings.interpreter, &logger);
4747
CPU.reset(settings.interpreter);
4848
IOD.input(0x0);
@@ -65,7 +65,7 @@ int main(int argc, char* args[]) {
6565
//Printing the settings
6666
cout << logger.getStringTime() << logger.info << "Settings:" << endl << settings << logger.reset << endl;
6767
//Render the window
68-
RenderWindow window("RISC-CPU SIMULATOR v1.1.1", settings.win.width, settings.win.height,
68+
RenderWindow window("RISC-CPU SIMULATOR v1.1.2", settings.win.width, settings.win.height,
6969
flags, &logger, &settings, "res/icon-64.png");
7070
SDL_ShowCursor(0);
7171

@@ -393,7 +393,6 @@ int main(int argc, char* args[]) {
393393
constantFullInstruction = false;
394394
settings = JsonManager::getSettings();
395395
SB = SystemBus();
396-
CM.reset(settings.interpreter.ramSize);
397396
IOD.reset();
398397
CM.loadProgram(&settings.interpreter, &logger);
399398
CPU.reset(settings.interpreter);

src/risc.cpp

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ Uint16 ArithmeticLogicUnit::get(Uint8 r) {
184184
return R[r];
185185
}
186186

187-
CentralProcessingUnit::CentralProcessingUnit(SystemBus* pSB, CentralMemory* pCM, InputOutputDevices* pIOD, InterpreterSettings settings)
188-
:ALU(ArithmeticLogicUnit(&SR)), SB(pSB), CM(pCM), IOD(pIOD), PC(settings.start), phaseNow(0xFF), phaseNext(0x0), instName("-----"),
189-
SP(settings.ramSize - 2), IR(0x0), AR(0x0), DR(0x0) {}
187+
CentralProcessingUnit::CentralProcessingUnit(SystemBus* pSB, CentralMemory* pCM, InputOutputDevices* pIOD)
188+
:ALU(ArithmeticLogicUnit(&SR)), SB(pSB), CM(pCM), IOD(pIOD), PC(0), phaseNow(0xFF), phaseNext(0x0), instName("-----"),
189+
SP(0), IR(0x0), AR(0x0), DR(0x0) {}
190190

191191
void CentralProcessingUnit::reset(InterpreterSettings settings) {
192192
PC = settings.start;
@@ -780,15 +780,16 @@ void CentralProcessingUnit::outb() {
780780
}
781781

782782
void CentralProcessingUnit::tsti() {
783-
if(SB->getData() == 0x1) {
783+
if(SB->getData() == 0x1)
784784
SR.Z = IOD->getSent();
785-
}
786785
else SR.Z = 0;
787786
PC += 2;
788787
}
789788

790789
void CentralProcessingUnit::tsto() {
791-
SR.Z = (SB->getData() == 0x0);
790+
if(SB->getData() == 0x0)
791+
SR.Z = IOD->getReceived();
792+
else SR.Z = 0;
792793
PC += 2;
793794
}
794795

@@ -853,11 +854,7 @@ void CentralProcessingUnit::hlt() {
853854
phaseNext = 0xF0;
854855
}
855856

856-
CentralMemory::CentralMemory(SystemBus* pSB, Uint32 psize) :SB(pSB), size(psize) {
857-
for(Uint32 i = 0; i < size; i++) {
858-
M.push_back(0x00);
859-
}
860-
}
857+
CentralMemory::CentralMemory(SystemBus* pSB) :SB(pSB), size(0) {}
861858

862859
void CentralMemory::reset(Uint32 psize) {
863860
size = psize;
@@ -876,12 +873,14 @@ void CentralMemory::loadProgram(InterpreterSettings* settings, Logger* logger) {
876873
char s[100];
877874
switch(settings->type) {
878875
case 0:
876+
reset(settings->ramSize);
879877
for(Uint32 i = 0; i < size && !file.eof(); i++) {
880878
file.getline(s, 100);
881879
M[i] = math::binstrToUint8(s);
882880
}
883881
break;
884882
case 1:
883+
reset(settings->ramSize);
885884
for(Uint32 i = 0; i < size && !file.eof(); i++) {
886885
file.getline(s, 100);
887886
M[i] = math::hexstrToUint8(s);
@@ -1171,10 +1170,11 @@ void CentralMemory::loadProgram(InterpreterSettings* settings, Logger* logger) {
11711170
<< logger->reset << endl;
11721171
settings->file = settings->file + ".hex";
11731172
settings->type = 1;
1174-
settings->ramSize = hexLines.size() + 0xF0;
1173+
settings->ramSize = hexLines.size() + 0xF0; settings->ramSize -= settings->ramSize % 2;
11751174
for(Label l : labelAddressAssociations) {
11761175
if(l.name == "START") {
11771176
settings->start = l.address;
1177+
break;
11781178
}
11791179
}
11801180
loadProgram(settings, logger);
@@ -1194,9 +1194,8 @@ void CentralMemory::operate() {
11941194
if(!CB.M) return;
11951195
if(AB >= size) return;
11961196
if(CB.R) {
1197-
if(!CB.W) {
1197+
if(!CB.W)
11981198
DB = M[AB];
1199-
}
12001199
else {
12011200
Uint8 a;
12021201
Uint16 b;
@@ -1207,9 +1206,8 @@ void CentralMemory::operate() {
12071206
SB->writeData(DB);
12081207
}
12091208
else {
1210-
if(!CB.W) {
1209+
if(!CB.W)
12111210
M[AB] = DB;
1212-
}
12131211
else {
12141212
Uint8 a, b;
12151213
a = DB & 0xFF;
@@ -1226,11 +1224,13 @@ Uint8 CentralMemory::get(Uint16 address) {
12261224
}
12271225

12281226
InputOutputDevices::InputOutputDevices(SystemBus* pSB) :SB(pSB) {
1229-
sent = false;
1227+
reset();
12301228
}
12311229

12321230
void InputOutputDevices::reset() {
12331231
line0 = line1 = line2 = line3 = "";
1232+
sent = false;
1233+
received = false;
12341234
}
12351235

12361236
void InputOutputDevices::input(Uint8 i) {
@@ -1304,6 +1304,7 @@ void InputOutputDevices::operate() {
13041304
else {
13051305
line0 += s;
13061306
}
1307+
received = true;
13071308
}
13081309
else if(address == 0x1 && control.R) { //Input keyboard
13091310
SB->writeData(key);
@@ -1324,5 +1325,13 @@ bool InputOutputDevices::getSent() {
13241325
sent = false;
13251326
return true;
13261327
}
1327-
else return false;
1328+
return false;
1329+
}
1330+
1331+
bool InputOutputDevices::getReceived() {
1332+
if(received) {
1333+
received = false;
1334+
return true;
1335+
}
1336+
return false;
13281337
}

0 commit comments

Comments
 (0)