-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from 710lucas/feat#16/add-display-as-io-device
Feat#16/add display as io device
- Loading branch information
Showing
10 changed files
with
284 additions
and
19 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
//Adding F9 to register 1 | ||
//F9: Display pixel | ||
//byte 0 | ||
ADD 0xFFF9 0xFF00 0x0001 | ||
|
||
//Telling bus to add pixel to display | ||
//byte 6 | ||
WBUS 0xFF00 0xFF00 0x0001 | ||
|
||
//I'll write "RISC-I" in memory, letter by letter | ||
|
||
//Adding R to register 2 | ||
//R = 0x52 in ACII | ||
ADD 0xFF52 0xFF00 0x0002 | ||
|
||
//Writing R to memory | ||
STL 0xFFA0 0xFF00 0x0002 | ||
|
||
|
||
//Adding I to register 2 | ||
//I = 0x49 in ACII | ||
ADD 0xFF49 0xFF00 0x0002 | ||
|
||
//writing I to memory | ||
STL 0xFFA1 0xFF00 0x0002 | ||
|
||
|
||
|
||
//Adding S to register 2 | ||
//S = 0x53 in ACII | ||
ADD 0xFF53 0xFF00 0x0002 | ||
|
||
//writing S to memory | ||
STL 0xFFA2 0xFF00 0x0002 | ||
|
||
|
||
//Adding C to register 2 | ||
//C = 0x43 in ACII | ||
ADD 0xFF43 0xFF00 0x0002 | ||
|
||
//writing C to memory | ||
STL 0xFFA3 0xFF00 0x0002 | ||
|
||
|
||
//Adding - to register 2 | ||
//- = 0x2D in ACII | ||
ADD 0xFF2D 0xFF00 0x0002 | ||
|
||
//writing - to memory | ||
STL 0xFFA4 0xFF00 0x0002 | ||
|
||
|
||
//Adding I to register 2 | ||
//I = 0x49 in ACII | ||
ADD 0xFF49 0xFF00 0x0002 | ||
|
||
//writing I to memory | ||
STL 0xFFA5 0xFF00 0x0002 | ||
|
||
|
||
|
||
//Adding instruction to display text | ||
//in register 3 | ||
ADD 0xFFFA 0xFF00 0x0003 | ||
|
||
//Size of the text: 6 -> 0xFF01 | ||
//Address of text: 0xFFA0 | ||
//Control: 0x0003 | ||
WBUS 0xFF06 0xFFA0 0x0003 | ||
|
||
STP 0x0000 0x0000 0x0000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#include "display.hpp" | ||
|
||
Display::Display(SystemBus &bus) : IOInterface(bus){ | ||
} | ||
|
||
void Display::write(byte data){ | ||
} | ||
|
||
void Display::read(long address){ | ||
} | ||
|
||
void Display::displayText(byte address, byte size){ | ||
|
||
std::string text = ""; | ||
for(int i = 0; i < size; i++){ | ||
this->getBus()->writeAddress(address+i); | ||
this->getBus()->writeControl(MEMREAD); | ||
this->getBus()->execute(); | ||
text += static_cast<char>(this->getBus()->readData()); | ||
} | ||
|
||
this->displayTexts.push_back({text, x, y}); | ||
|
||
} | ||
|
||
void Display::displayPixel(){ | ||
|
||
Rectangle pixel = {x, y, 1, 1}; | ||
|
||
this->displayRects.push_back(pixel); | ||
} | ||
|
||
void Display::clearDisplay(){ | ||
ClearBackground(WHITE); | ||
} | ||
|
||
void Display::clearPixel(){ | ||
|
||
for(int i = 0; i < displayRects.size(); i++){ | ||
|
||
Rectangle rect = displayRects[i]; | ||
|
||
if(rect.x == x && rect.y == y){ | ||
displayRects.erase(displayRects.begin() + i); | ||
break; | ||
} | ||
} | ||
|
||
} | ||
|
||
void Display::setX(int x){ | ||
this->x = x; | ||
} | ||
|
||
void Display::setY(int y){ | ||
this->y = y; | ||
} | ||
|
||
byte Display::execute(byte control, byte address, byte data){ | ||
switch(control){ | ||
case SETCRDX: | ||
this->setX(static_cast<int>(data)); | ||
break; | ||
case SETCRDY: | ||
this->setY(static_cast<int>(data)); | ||
break; | ||
case PXDSPL: | ||
this->displayPixel(); | ||
break; | ||
case TXTDSPL: | ||
this->displayText(address, data); | ||
break; | ||
case CLRDSPL: | ||
clearDisplay(); | ||
break; | ||
case CLRPXL: | ||
clearPixel(); | ||
break; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
|
||
void Display::displayLoop(){ | ||
ClearBackground(WHITE); | ||
BeginDrawing(); | ||
|
||
for(const auto& rect: displayRects){ | ||
DrawRectangle(rect.x, rect.y, rect.width*(GetScreenWidth()/64), rect.height*(GetScreenHeight()/64), BLACK); | ||
} | ||
|
||
for(const auto& text: displayTexts){ | ||
DrawText(text.text.c_str(), text.x, text.y, 20*(GetScreenHeight()/64), BLACK); | ||
} | ||
|
||
EndDrawing(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#pragma once | ||
|
||
#include "../IO.hpp" | ||
#include "../../BUS/systemBus.hpp" | ||
#include <vector> | ||
#include <iostream> | ||
#include "raylib.h" | ||
|
||
struct Text{ | ||
std::string text; | ||
int x; | ||
int y; | ||
}; | ||
|
||
|
||
class Display : public IOInterface{ | ||
|
||
private: | ||
std::vector<Rectangle> displayRects; | ||
std::vector<Text> displayTexts; | ||
|
||
int x = 0; | ||
int y = 0; | ||
|
||
|
||
public: | ||
Display(SystemBus &bus); | ||
|
||
void displayText(byte address, byte size); | ||
|
||
void displayPixel(); | ||
|
||
void clearDisplay(); | ||
|
||
void clearPixel(); | ||
|
||
void setX(int x); | ||
void setY(int y); | ||
|
||
//Write to display | ||
virtual void write(byte data) override; | ||
|
||
//Read from display | ||
virtual void read(long address) override; | ||
|
||
//Execute IO operation | ||
virtual byte execute(byte control, byte address, byte data) override; | ||
|
||
void displayLoop(); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.