-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevices.cpp
More file actions
53 lines (41 loc) · 987 Bytes
/
Copy pathdevices.cpp
File metadata and controls
53 lines (41 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdexcept>
#include "devices.h"
namespace devices {
Keyboard::Keyboard() {
this -> keys.resize(KEYS);
}
Screen::Screen() {
this -> gfx.resize(W*H);
set_draw(true);
}
void Screen::clearScreen() {
for(int i=0; i<W; i++) {
for(int j=0; j<H; j++) {
this -> gfx[i + j] = 0;
}
}
set_draw(true);
}
unsigned char Screen::get_at(unsigned short x, unsigned short y){
return this -> gfx[x + y*W];
}
void Screen::set_at(unsigned short x, unsigned short y, unsigned char value){
this->gfx[x + y*W] = value;
}
bool Screen::is_draw(){
return this->draw_flag;
}
void Screen::set_draw(bool draw_flag){
this->draw_flag = draw_flag;
}
unsigned char Keyboard::get_key_at(int key){
if(key > KEYS - 1) {
throw std::runtime_error("Key out of bound"+std::to_string(key));
}
return this->keys[key];
}
void Keyboard::set_key_at(int key, unsigned char value){
this->keys[key] = value;
}
int Keyboard::get_size() { return KEYS; }
}