Skip to content

Commit 3c331d3

Browse files
committed
[logo] Add 'fd', 'bk', 'rt', 'lt' commands
1 parent 8db32c6 commit 3c331d3

File tree

16 files changed

+367
-34
lines changed

16 files changed

+367
-34
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ binaries: $(bt_stage1) $(bt_stage2) $(kernel_core) $(rm_static)
111111
SECTOR_COUNT_BT_STAGE1 = 1
112112
SECTOR_COUNT_SHARED_LIBRARY = 1
113113
SECTOR_COUNT_BT_STAGE2 = 12
114-
SECTOR_COUNT_KERNEL = 75
114+
SECTOR_COUNT_KERNEL = 80
115115

116116
SECTOR_START_BT_STAGE1 = 0
117117
SECTOR_START_SHARED_LIBRARY = $(shell expr $(SECTOR_START_BT_STAGE1) + $(SECTOR_COUNT_BT_STAGE1) )

src/usr/include/iostream.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class ostream {
1111
public:
1212
ostream& operator<<(const char c);
1313
ostream& operator<<(const int num);
14+
ostream& operator<<(const double num);
1415
ostream& operator<<(const std::string &str);
1516
ostream& operator<<(const char* str);
1617
};
@@ -20,6 +21,7 @@ class istream {
2021
istream& operator>>(char &c);
2122
istream& operator>>(char *str);
2223
istream& operator>>(std::string &str);
24+
istream& operator>>(int &x);
2325

2426
istream& get(char &c);
2527
istream& get_line(char *str, std::size_t n, char delim='\n');

src/usr/include/limits.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
3+
#define LLONG_MAX 9223372036854775807LL
4+
#define LLONG_MIN (-LLONG_MAX-1)
5+
#define ULLONG_MAX ((unsigned long)(((unsigned long)LLONG_MAX)*2ULL+1))
6+
7+
#define INT_MAX 2147483647
8+
#define INT_MIN (-INT_MAX-1)
9+
#define UINT_MAX ((unsigned int)(((unsigned int)INT_MAX)*2U+1))

src/usr/include/math.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
3+
#define M_PI 3.14159265358979323846
4+
5+
#ifdef __cplusplus
6+
extern "C" {
7+
namespace std {
8+
#endif
9+
10+
int isnan(double x);
11+
double floor(double x);
12+
double round(double x);
13+
double fmod(double x, double y);
14+
15+
double sin(double x);
16+
double cos(double x);
17+
18+
#ifdef __cplusplus
19+
} // namespace std end
20+
} // extern C end
21+
#endif

src/usr/include/stdlib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ int atoi (const char *s);
1313
// for others the result can be undefined.
1414
// And only base 10 is considered as signed int.
1515
void itoa(int num, char *s, int base);
16+
void ftoa(double num, char *s);
1617
int min(int, int);
1718
int max(int, int);
1819
int abs(int a);

src/usr/include/string.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class basic_string {
3434
std::vector<CharT> _data;
3535

3636
public:
37+
const static std::size_t npos = -1;
38+
3739
typedef CharT* iterator;
3840
typedef const CharT* const_iterator;
3941

@@ -55,6 +57,10 @@ class basic_string {
5557
CharT& at(std::size_t pos);
5658
CharT& operator[](std::size_t pos);
5759
const CharT *c_str() const;
60+
std::size_t length() const;
61+
62+
std::size_t find(char c, std::size_t pos = 0) const;
63+
basic_string<CharT> substr(int start, std::size_t len = npos);
5864

5965
basic_string<CharT>& operator=(const basic_string<CharT>& o);
6066
basic_string<CharT>& operator+=(const CharT c);

src/usr/include/string.tcc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,38 @@ const CharT *basic_string<CharT>::c_str() const {
8383
return this->_data.begin();
8484
}
8585

86+
template <typename CharT>
87+
std::size_t basic_string<CharT>::length() const {
88+
std::size_t sz = this->_data.size();
89+
if(sz == 0) {
90+
return 0; // should not happen
91+
}
92+
return sz - 1;
93+
}
94+
95+
template <typename CharT>
96+
std::size_t basic_string<CharT>::find(char c, std::size_t pos) const {
97+
std::size_t len = length();
98+
while (pos < len) {
99+
if (this->_data[pos] == c) {
100+
return pos;
101+
}
102+
pos++;
103+
}
104+
return npos;
105+
}
106+
107+
template <typename CharT>
108+
basic_string<CharT> basic_string<CharT>::substr(int start, std::size_t len) {
109+
std::string sub;
110+
int index = start;
111+
int str_length = length();
112+
for(std::size_t i = 0; i < len && index < str_length; i++, index++) {
113+
sub += this->at(index);
114+
}
115+
return sub;
116+
}
117+
86118
template <typename CharT>
87119
basic_string<CharT>& basic_string<CharT>::operator=(const basic_string<CharT> &o) {
88120
this->_data = o._data;

src/usr/include/vector.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ class vector {
2626
const_iterator end() const;
2727

2828
void clear();
29-
bool empty();
30-
std::size_t size();
29+
bool empty() const;
30+
std::size_t size() const;
3131
void push_back(const T &val);
3232
void pop_back();
3333

3434
T& back();
3535
T& front();
3636
T& at(std::size_t pos);
3737
T& operator[](std::size_t pos);
38+
const T& operator[](std::size_t pos) const;
3839
};
3940

4041
} // namespace std end

src/usr/include/vector.tcc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ void vector<T>::clear() {
8282
}
8383

8484
template <typename T>
85-
bool vector<T>::empty() {
85+
bool vector<T>::empty() const {
8686
return this->_size == 0;
8787
}
8888

8989
template <typename T>
90-
std::size_t vector<T>::size() {
90+
std::size_t vector<T>::size() const {
9191
return this->_size;
9292
}
9393

@@ -127,4 +127,9 @@ T &vector<T>::operator[](std::size_t pos) {
127127
return this->_data[pos];
128128
}
129129

130+
template <typename T>
131+
const T &vector<T>::operator[](std::size_t pos) const {
132+
return this->_data[pos];
133+
}
134+
130135
} // namespace std end

src/usr/lib/graphics.c

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ static struct GraphicsState {
1111
int x, y;
1212
} gstate = {0};
1313

14-
static uint8_t BUFFER[GRAPHICS_MAX_HEIGHT][GRAPHICS_MAX_WIDTH]={0};
14+
static uint8_t __BUFFER[GRAPHICS_MAX_HEIGHT][GRAPHICS_MAX_WIDTH]={0};
15+
static inline write_buffer(int x, int y, uint8_t color) {
16+
if(x>=0 && x<GRAPHICS_MAX_WIDTH && y>=0 && y<GRAPHICS_MAX_HEIGHT) {
17+
__BUFFER[y][x] = color;
18+
} // otherwise just ignore
19+
}
1520

1621
void initgraph(int *graphdetect, int *graphmode, char *not_used) {
1722
if (*graphdetect == DETECT) {
@@ -50,12 +55,12 @@ static void _autoflushnow() {
5055
}
5156

5257
int graphflush() {
53-
gstate.last_err = SYSCALL_A2(SYSCALL_GRAPHICS, SYSCALL_GRAPHICS_COPYBUFFER, BUFFER);
58+
gstate.last_err = SYSCALL_A2(SYSCALL_GRAPHICS, SYSCALL_GRAPHICS_COPYBUFFER, __BUFFER);
5459
return gstate.last_err;
5560
}
5661

5762
void cleardevice() {
58-
memset(BUFFER, gstate.bkcolor, sizeof(BUFFER));
63+
memset(__BUFFER, gstate.bkcolor, sizeof(__BUFFER));
5964
moveto(0, 0);
6065
_autoflushnow();
6166
}
@@ -89,12 +94,31 @@ int getbkcolor() {
8994
}
9095

9196
void putpixel(int x, int y, int color) {
92-
BUFFER[y][x]=color;
97+
write_buffer(x, y, color);
9398
_autoflushnow();
9499
}
95100

96101
void line(int x1, int y1, int x2, int y2) {
97102
const int color = getcolor();
103+
if(x1==x2) {
104+
if(y1>y2) {
105+
int t = y1; y1 = y2; y2 = t;
106+
}
107+
for(int y=y1; y<=y2; y++) {
108+
write_buffer(x1, y, color);
109+
}
110+
return;
111+
}
112+
if(y1==y2) {
113+
if(x1>x2) {
114+
int t = x1; x1 = x2; x2 = t;
115+
}
116+
for(int x=x1; x<=x2; x++) {
117+
write_buffer(x, y1, color);
118+
}
119+
return;
120+
}
121+
98122
if(abs(x1-x2)>=abs(y1-y2)) {
99123
// horizontal length is longer
100124
if(x1>x2) {
@@ -106,8 +130,8 @@ void line(int x1, int y1, int x2, int y2) {
106130
const int xdiff = x2-x1;
107131
const int ydiff = y2-y1;
108132
for (int x = x1; x <= x2; x++) {
109-
int y = ydiff*(x-x1)/xdiff;
110-
BUFFER[y][x]=color;
133+
int y = ydiff*(x-x1)/xdiff + y1;
134+
write_buffer(x, y, color);
111135
}
112136
} else {
113137
// vertical length is longer
@@ -120,8 +144,8 @@ void line(int x1, int y1, int x2, int y2) {
120144
const int xdiff = x2-x1;
121145
const int ydiff = y2-y1;
122146
for (int y = y1; y <= y2; y++) {
123-
int x = y*xdiff/ydiff+x1;
124-
BUFFER[y][x]=color;
147+
int x = (y-y1)*xdiff/ydiff+x1;
148+
write_buffer(x, y, color);
125149
}
126150
}
127151
_autoflushnow();
@@ -139,12 +163,12 @@ void rectangle(int left, int top, int right, int bottom) {
139163
const int color = getcolor();
140164

141165
for(int x=left;x<=right;x++) {
142-
BUFFER[top][x]=color;
143-
BUFFER[bottom][x]=color;
166+
write_buffer(x, top, color);
167+
write_buffer(x, bottom, color);
144168
}
145169
for(int y=top+1;y<bottom;y++) {
146-
BUFFER[y][left]=color;
147-
BUFFER[y][right]=color;
170+
write_buffer(left, y, color);
171+
write_buffer(right, y, color);
148172
}
149173
_autoflushnow();
150174
}
@@ -154,7 +178,7 @@ void bar(int left, int top, int right, int bottom) {
154178

155179
for(int y=top;y<=bottom;y++) {
156180
for(int x=left;x<=right;x++) {
157-
BUFFER[y][x]=color;
181+
write_buffer(x, y, color);
158182
}
159183
}
160184
_autoflushnow();
@@ -181,7 +205,7 @@ void fillellipse(int xcenter, int ycenter, int x_radius, int y_radius) {
181205
int fx = xcenter + x;
182206
int fy = ycenter + y;
183207
if(fx>=0 && fy>=0 && fx<GRAPHICS_MAX_WIDTH && fy<GRAPHICS_MAX_HEIGHT) {
184-
BUFFER[fy][fx]=color;
208+
write_buffer(fx, fy, color);
185209
}
186210
}
187211
}
@@ -339,7 +363,7 @@ static void draw_font(char c, int x, int y) {
339363
uint8_t frow = font[c][j];
340364
for(int i=0; i < 8; i++) if(x+i>=0 && x+i<GRAPHICS_MAX_WIDTH) {
341365
if((frow&mask)) {
342-
BUFFER[y+j][x+i] = color;
366+
write_buffer(x+i, y+j, color);
343367
}
344368
mask<<=1;
345369
}

0 commit comments

Comments
 (0)