Skip to content

Commit 2a8b0e9

Browse files
committed
1.1.1: Added TSTI and TSTO, fixed bug with labels before BYTE and WORD
1 parent 189ac06 commit 2a8b0e9

File tree

7 files changed

+111
-51
lines changed

7 files changed

+111
-51
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.0
8+
VERSION = 1.1.1
99
NAME = risc-sim
1010

1111
default:

README.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@
133133
║ │ + OUTB: to output a byte to monitor │ ║
134134
║ │ - assembly: OUTB Rs hhhh │ ║
135135
║ │ - binary: 10000011ssss0000 hexadecimal: 83s0 status register: Z:-, N:-, C:-, V:- │ ║
136+
║ │ + TSTI: to test if an input operation has been completed (Z = 1) or not (Z = 0) │ ║
137+
║ │ - assembly: TSTI hhhh │ ║
138+
║ │ - 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) │ ║
140+
║ │ - assembly: TSTO hhhh │ ║
141+
║ │ - binary: 1000010100000000 hexadecimal: 8500 status register: Z:D, N:-, C:-, V:- │ ║
136142
║ │ ! WARNING: I/O instructions have to be followed by the address (x16) of the I/O device │ ║
137143
║ │ ! \n (0x0A) will move all lines up by one, but will not move to a new line │ ║
138144
║ │ ! \r (0x0D) will move to a new line, but will not move all lines up by one │ ║

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

include/risc.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,14 @@ class CentralProcessingUnit{
385385
* @brief Function to output a byte
386386
*/
387387
void outb();
388+
/**
389+
* @brief Function to test if the input operation has been completed
390+
*/
391+
void tsti();
392+
/**
393+
* @brief Function to test if the output operation has been completed
394+
*/
395+
void tsto();
388396
/**
389397
* @brief Function to modify the program counter with an address after the instruction
390398
*/
@@ -494,8 +502,14 @@ class InputOutputDevices {
494502
* @param l3 Reference to the string for the line 3
495503
*/
496504
void getLines(string &l0, string &l1, string &l2, string &l3);
505+
/**
506+
* @brief Function to see if a key byte was sent from the keyboard, not 0x00
507+
* @returns True if a key byte was sent, false if 0x00 or nothing was sent
508+
*/
509+
bool getSent();
497510
private:
498511
SystemBus* SB; //System Bus pointer
499512
Uint8 key;
500513
string line0, line1, line2, line3;
514+
bool sent;
501515
};

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": "rsh.asm",
3+
"file": "tst.asm",
44
"ram_size": 100,
55
"start": 0
66
},

src/main.cpp

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ int main(int argc, char* args[]) {
3232
bool clicked = false, refresh = true, constantRefresh = false;
3333
bool fullInstruction = false, constantFullInstruction = false, progressBarAll = false;
3434
Uint8 key; //For keyboard input
35+
bool shiftPressed = false;
3536

3637
//Capturing cout in log file
3738
if(settings.console.log) freopen("log.txt", "w", stdout);
@@ -64,7 +65,7 @@ int main(int argc, char* args[]) {
6465
//Printing the settings
6566
cout << logger.getStringTime() << logger.info << "Settings:" << endl << settings << logger.reset << endl;
6667
//Render the window
67-
RenderWindow window("RISC-CPU SIMULATOR v1.1.0", settings.win.width, settings.win.height,
68+
RenderWindow window("RISC-CPU SIMULATOR v1.1.1", settings.win.width, settings.win.height,
6869
flags, &logger, &settings, "res/icon-64.png");
6970
SDL_ShowCursor(0);
7071

@@ -303,25 +304,25 @@ int main(int argc, char* args[]) {
303304
case SDL_KEYDOWN:
304305
if(code >= SDL_SCANCODE_A && code <= SDL_SCANCODE_Z) {
305306
key = code + 93;
307+
if(shiftPressed) key -= 0x20;
306308
}
307-
else if(code >= SDL_SCANCODE_1 && code <= SDL_SCANCODE_9) {
309+
else if(code >= SDL_SCANCODE_1 && code <= SDL_SCANCODE_9)
308310
key = code + 19;
309-
}
310-
else if(code >= SDL_SCANCODE_KP_1 && code <= SDL_SCANCODE_KP_9) {
311+
else if(code >= SDL_SCANCODE_KP_1 && code <= SDL_SCANCODE_KP_9)
311312
key = code - 40;
312-
}
313-
else if(code == SDL_SCANCODE_0 || code == SDL_SCANCODE_KP_0) {
313+
else if(code == SDL_SCANCODE_0 || code == SDL_SCANCODE_KP_0)
314314
key = '0';
315-
}
316-
else if(code == SDL_SCANCODE_RETURN || code == SDL_SCANCODE_KP_ENTER) {
315+
else if(code == SDL_SCANCODE_RETURN || code == SDL_SCANCODE_KP_ENTER)
317316
key = '\r';
318-
}
319-
else if(code == SDL_SCANCODE_SPACE || code == SDL_SCANCODE_KP_SPACE) {
317+
else if(code == SDL_SCANCODE_SPACE || code == SDL_SCANCODE_KP_SPACE)
320318
key = ' ';
321-
}
319+
else if(!shiftPressed && (code == SDL_SCANCODE_LSHIFT || code == SDL_SCANCODE_RSHIFT))
320+
shiftPressed = true;
322321
IOD.input(key);
323322
break;
324323
case SDL_KEYUP:
324+
if(shiftPressed && (code == SDL_SCANCODE_LSHIFT || code == SDL_SCANCODE_RSHIFT))
325+
shiftPressed = false;
325326
key = 0x0;
326327
IOD.input(key);
327328
break;
@@ -475,32 +476,32 @@ int main(int argc, char* args[]) {
475476
case '8': indexKey = 7; break;
476477
case '9': indexKey = 8; break;
477478
case '0': indexKey = 9; break;
478-
case 'q': indexKey = 10; break;
479-
case 'w': indexKey = 11; break;
480-
case 'e': indexKey = 12; break;
481-
case 'r': indexKey = 13; break;
482-
case 't': indexKey = 14; break;
483-
case 'y': indexKey = 15; break;
484-
case 'u': indexKey = 16; break;
485-
case 'i': indexKey = 17; break;
486-
case 'o': indexKey = 18; break;
487-
case 'p': indexKey = 19; break;
488-
case 'a': indexKey = 20; break;
489-
case 's': indexKey = 21; break;
490-
case 'd': indexKey = 22; break;
491-
case 'f': indexKey = 23; break;
492-
case 'g': indexKey = 24; break;
493-
case 'h': indexKey = 25; break;
494-
case 'j': indexKey = 26; break;
495-
case 'k': indexKey = 27; break;
496-
case 'l': indexKey = 28; break;
497-
case 'z': indexKey = 29; break;
498-
case 'x': indexKey = 30; break;
499-
case 'c': indexKey = 31; break;
500-
case 'v': indexKey = 32; break;
501-
case 'b': indexKey = 33; break;
502-
case 'n': indexKey = 34; break;
503-
case 'm': indexKey = 35; break;
479+
case 'q': case 'Q': indexKey = 10; break;
480+
case 'w': case 'W': indexKey = 11; break;
481+
case 'e': case 'E': indexKey = 12; break;
482+
case 'r': case 'R': indexKey = 13; break;
483+
case 't': case 'T': indexKey = 14; break;
484+
case 'y': case 'Y': indexKey = 15; break;
485+
case 'u': case 'U': indexKey = 16; break;
486+
case 'i': case 'I': indexKey = 17; break;
487+
case 'o': case 'O': indexKey = 18; break;
488+
case 'p': case 'P': indexKey = 19; break;
489+
case 'a': case 'A': indexKey = 20; break;
490+
case 's': case 'S': indexKey = 21; break;
491+
case 'd': case 'D': indexKey = 22; break;
492+
case 'f': case 'F': indexKey = 23; break;
493+
case 'g': case 'G': indexKey = 24; break;
494+
case 'h': case 'H': indexKey = 25; break;
495+
case 'j': case 'J': indexKey = 26; break;
496+
case 'k': case 'K': indexKey = 27; break;
497+
case 'l': case 'L': indexKey = 28; break;
498+
case 'z': case 'Z': indexKey = 29; break;
499+
case 'x': case 'X': indexKey = 30; break;
500+
case 'c': case 'C': indexKey = 31; break;
501+
case 'v': case 'V': indexKey = 32; break;
502+
case 'b': case 'B': indexKey = 33; break;
503+
case 'n': case 'N': indexKey = 34; break;
504+
case 'm': case 'M': indexKey = 35; break;
504505
}
505506
for(Uint8 i = 0; i < 36; i++) {
506507
iodKeyEntities[i].setTexture(((i == indexKey) ? iodKeyPressedTexture : iodKeyTexture));

src/risc.cpp

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,12 @@ void CentralProcessingUnit::executeInstruction() {
405405
case 0x3:
406406
outb();
407407
break;
408+
case 0x4:
409+
tsti();
410+
break;
411+
case 0x5:
412+
tsto();
413+
break;
408414
default:
409415
phaseNext = 0xFF;
410416
}
@@ -591,12 +597,8 @@ string CentralProcessingUnit::decodeInstName() {
591597
return "ERR!";
592598
}
593599
switch(I.opcode) {
594-
case 0x0:
595-
return "INW";
596600
case 0x1:
597601
return "INB";
598-
case 0x2:
599-
return "OUTW";
600602
case 0x3:
601603
return "OUTB";
602604
case 0x4:
@@ -777,6 +779,19 @@ void CentralProcessingUnit::outb() {
777779
PC += 2;
778780
}
779781

782+
void CentralProcessingUnit::tsti() {
783+
if(SB->getData() == 0x1) {
784+
SR.Z = IOD->getSent();
785+
}
786+
else SR.Z = 0;
787+
PC += 2;
788+
}
789+
790+
void CentralProcessingUnit::tsto() {
791+
SR.Z = (SB->getData() == 0x0);
792+
PC += 2;
793+
}
794+
780795
void CentralProcessingUnit::br() {
781796
PC = SB->getData();
782797
}
@@ -933,7 +948,7 @@ void CentralMemory::loadProgram(InterpreterSettings* settings, Logger* logger) {
933948
if(spacePos != string::npos) {
934949
arg2 = l.substr(spacePos + 1);
935950
}
936-
if(inst.substr(0, 2) == "LD") {
951+
if(inst.substr(0, 2) == "LD" && inst.length() == 4) {
937952
switch(inst[3]) {
938953
case 'I': //LDWI or LDBI
939954
hexLines.push_back(label + math::argumentToRegister(arg1) + "0");
@@ -963,7 +978,7 @@ void CentralMemory::loadProgram(InterpreterSettings* settings, Logger* logger) {
963978
else hexLines.push_back("31");
964979
}
965980
}
966-
else if(inst.substr(0, 2) == "ST") {
981+
else if(inst.substr(0, 2) == "ST" && inst.length() == 4) {
967982
switch(inst[3]) {
968983
case 'A': //STWA or STBA
969984
hexLines.push_back(label + math::argumentToRegister(arg1) + "0");
@@ -1053,6 +1068,13 @@ void CentralMemory::loadProgram(InterpreterSettings* settings, Logger* logger) {
10531068
for(string le : math::wordToLittleEndian(arg2))
10541069
hexLines.push_back(le);
10551070
}
1071+
else if(inst.substr(0, 3) == "TST" && inst.length() == 4) { //TSTI
1072+
hexLines.push_back(label + "00");
1073+
if(inst[3] == 'I') hexLines.push_back("84");
1074+
else hexLines.push_back("85");
1075+
for(string le : math::wordToLittleEndian(arg1))
1076+
hexLines.push_back(le);
1077+
}
10561078
else if(inst == "BR") { //BR
10571079
hexLines.push_back(label + "00");
10581080
hexLines.push_back("C0");
@@ -1062,7 +1084,7 @@ void CentralMemory::loadProgram(InterpreterSettings* settings, Logger* logger) {
10621084
else
10631085
hexLines.push_back(arg1); hexLines.push_back("");
10641086
}
1065-
else if(inst.substr(0, 3) == "JMP") {
1087+
else if(inst.substr(0, 3) == "JMP" && (inst.length() >= 3 && inst.length() <= 5)) {
10661088
hexLines.push_back(label + arg1);
10671089
if(inst.length() == 3) //JMP
10681090
hexLines.push_back("C1");
@@ -1097,11 +1119,12 @@ void CentralMemory::loadProgram(InterpreterSettings* settings, Logger* logger) {
10971119
hexLines.push_back("CF");
10981120
}
10991121
else if(inst == "WORD") { //WORD
1100-
for(string le : math::wordToLittleEndian(arg1))
1101-
hexLines.push_back(le);
1122+
vector<string> le = math::wordToLittleEndian(arg1);
1123+
hexLines.push_back(label + le[0]);
1124+
hexLines.push_back(le[1]);
11021125
}
11031126
else if(inst == "BYTE") { //BYTE
1104-
hexLines.push_back(arg1);
1127+
hexLines.push_back(label + arg1);
11051128
}
11061129
}
11071130
struct Label {
@@ -1202,7 +1225,9 @@ Uint8 CentralMemory::get(Uint16 address) {
12021225
return M[address];
12031226
}
12041227

1205-
InputOutputDevices::InputOutputDevices(SystemBus* pSB) :SB(pSB) {}
1228+
InputOutputDevices::InputOutputDevices(SystemBus* pSB) :SB(pSB) {
1229+
sent = false;
1230+
}
12061231

12071232
void InputOutputDevices::reset() {
12081233
line0 = line1 = line2 = line3 = "";
@@ -1282,6 +1307,7 @@ void InputOutputDevices::operate() {
12821307
}
12831308
else if(address == 0x1 && control.R) { //Input keyboard
12841309
SB->writeData(key);
1310+
sent = (key != 0x0);
12851311
key = 0x0;
12861312
}
12871313
}
@@ -1291,4 +1317,12 @@ void InputOutputDevices::getLines(string &l0, string &l1, string &l2, string &l3
12911317
l1 = line1;
12921318
l2 = line2;
12931319
l3 = line3;
1320+
}
1321+
1322+
bool InputOutputDevices::getSent() {
1323+
if(sent) {
1324+
sent = false;
1325+
return true;
1326+
}
1327+
else return false;
12941328
}

0 commit comments

Comments
 (0)