Skip to content

Commit 733941b

Browse files
committed
iod work in progress
1 parent 00db148 commit 733941b

File tree

5 files changed

+78
-2
lines changed

5 files changed

+78
-2
lines changed

include/risc.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,10 @@ class InputOutputDevices {
463463
* @param pSB System bus pointer
464464
*/
465465
InputOutputDevices(SystemBus* pSB);
466+
void input(Uint8 i);
467+
void operate();
466468
private:
467469
SystemBus* SB; //System Bus pointer
470+
Uint8 key;
471+
string line0, line1, line2, line3;
468472
};

res/img/iod_gui.png

803 Bytes
Loading

res/img/system_bus_gui.png

324 Bytes
Loading

src/main.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ int main(int argc, char* args[]) {
3131
Uint16 cellsStartAddress = 0x0; //For CM rendering
3232
bool clicked = false, refresh = true, constantRefresh = false;
3333
bool fullInstruction = false, constantFullInstruction = false, progressBarAll = false;
34+
Uint8 key; //For keyboard input
3435

3536
//Interpreter
3637
SystemBus SB;
@@ -70,6 +71,7 @@ int main(int argc, char* args[]) {
7071
SDL_Texture* fontTexture = Window.loadTexture("res/img/font.png");
7172
SDL_Texture* cpuGuiTexture = Window.loadTexture("res/img/cpu_gui.png");
7273
SDL_Texture* cmGuiTexture = Window.loadTexture("res/img/cm_gui.png");
74+
SDL_Texture* iodGuiTexture = Window.loadTexture("res/img/iod_gui.png");
7375
SDL_Texture* sbGuiTexture = Window.loadTexture("res/img/system_bus_gui.png");
7476
SDL_Texture* progressBarTexture = Window.loadTexture("res/img/progress_bar.png");
7577
SDL_Texture* progressBarNowTexture = Window.loadTexture("res/img/progress_bar_now.png");
@@ -90,7 +92,8 @@ int main(int argc, char* args[]) {
9092
//GUI backgrounds
9193
Entity cpuGui(Vector2f(6, 10), cpuGuiTexture, 256, 128);
9294
Entity cmGui(Vector2f(70, 10), cmGuiTexture, 256, 128);
93-
Entity sbGui(Vector2f(6, 121), sbGuiTexture, 128, 256);
95+
Entity iodGui(Vector2f(111, 58), iodGuiTexture, 256, 128);
96+
Entity sbGui(Vector2f(6, 121), sbGuiTexture, 128, 384);
9497
//Instruction name
9598
TextEntity instNameTitle(Vector2f(32, 3), fontTexture, &font);
9699
TextEntity instNameValue(Vector2f(82, 3), fontTexture, &font);
@@ -212,6 +215,7 @@ int main(int argc, char* args[]) {
212215
}
213216
msNext = msNow + msStep;
214217
clicked = false;
218+
key = 0x0;
215219
//Controls
216220
while(SDL_PollEvent(&event)) {
217221
switch(event.type) {
@@ -241,6 +245,25 @@ int main(int argc, char* args[]) {
241245
cellsStartAddress = settings.interpreter.ramSize - (4 - cellsStartAddress);
242246
}
243247
break;
248+
case SDL_KEYDOWN:
249+
SDL_Scancode code = event.key.keysym.scancode;
250+
if(code >= SDL_SCANCODE_A && code <= SDL_SCANCODE_Z) {
251+
key = code + 93;
252+
}
253+
else if(code >= SDL_SCANCODE_1 && code <= SDL_SCANCODE_9) {
254+
key = code + 19;
255+
}
256+
else if(code >= SDL_SCANCODE_KP_1 && code <= SDL_SCANCODE_KP_9) {
257+
key = code - 40;
258+
}
259+
else if(code == SDL_SCANCODE_0 || code == SDL_SCANCODE_KP_0) {
260+
key = '0';
261+
}
262+
else if(code == SDL_SCANCODE_KP_ENTER) {
263+
key = '\n';
264+
}
265+
IOD.input(key);
266+
break;
244267
}
245268
}
246269
//Actual processing
@@ -370,6 +393,7 @@ int main(int argc, char* args[]) {
370393
//GUI backgrounds
371394
Window.renderGui(cpuGui);
372395
Window.renderGui(cmGui);
396+
Window.renderGui(iodGui);
373397
Window.renderGui(sbGui);
374398
//CPU Render
375399
Window.renderText(cpuTitle);

src/risc.cpp

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,4 +877,52 @@ Uint8 CentralMemory::get(Uint16 address) {
877877
return M[address];
878878
}
879879

880-
InputOutputDevices::InputOutputDevices(SystemBus* pSB) :SB(pSB) {}
880+
InputOutputDevices::InputOutputDevices(SystemBus* pSB) :SB(pSB) {}
881+
882+
void InputOutputDevices::operate() {
883+
ControlBus control = SB->getControl();
884+
Uint16 address = SB->getAddress();
885+
Uint16 data = SB->getData();
886+
if(control.M) return;
887+
if(address == 0x0 && !control.R) { //Output monitor
888+
Uint16 data = SB->getData();
889+
if(data == '\n') {
890+
line0 = line1;
891+
line1 = line2;
892+
line2 = line3;
893+
line3 = "";
894+
}
895+
else if(line0.size() == 20) {
896+
if(line1.size() == 20) {
897+
if(line2.size() == 20) {
898+
if(line3.size() == 20) {
899+
line0 = line1;
900+
line1 = line2;
901+
line2 = line3;
902+
line3 = char(data);
903+
}
904+
else {
905+
line3 += char(data);
906+
}
907+
}
908+
else {
909+
line2 += char(data);
910+
}
911+
}
912+
else {
913+
line1 += char(data);
914+
}
915+
}
916+
else {
917+
line0 += char(data);
918+
}
919+
}
920+
else if(address == 0x1 && control.R) { //Input keyboard
921+
SB->writeData(key);
922+
key = 0x0;
923+
}
924+
}
925+
926+
void InputOutputDevices::input(Uint8 i) {
927+
key = i;
928+
}

0 commit comments

Comments
 (0)