-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
119 lines (108 loc) · 2.22 KB
/
main.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <iostream>
#include <glfw/glfw3.h>
#include "Console/Headers/display.h"
#include "Console/Headers/console.h"
#include "Eigenmath/Headers/defs.h"
GLFWwindow *win;
const int scale = 2;
unsigned char vram[VRAM_SIZE_BYTE];
void Init(void)
{
glfwInit();
win = glfwCreateWindow(SCREEN_WIDTH * scale, SCREEN_HEIGHT * scale, "Display", NULL, NULL);
glfwMakeContextCurrent(win);
glClearColor(1.0, 1.0, 1.0, 1.0);
glTranslated(-1.0, 1.0, 0);
glScaled(2.0 / SCREEN_WIDTH, -2.0 / SCREEN_HEIGHT, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glfwSetWindowSizeLimits(win, SCREEN_WIDTH * scale, SCREEN_HEIGHT * scale, SCREEN_WIDTH * scale, SCREEN_HEIGHT * scale);
}
inline void DrawPixel(int x, int y)
{
glColor3ub(0, 0, 0);
glBegin(GL_QUADS);
{
glVertex2d(x, y);
glVertex2d(x, y + 1);
glVertex2d(x + 1, y + 1);
glVertex2d(x + 1, y);
}
glEnd();
}
inline void ClearPixel(int x, int y)
{
glColor3ub(235, 235, 235);
glBegin(GL_QUADS);
{
glVertex2d(x, y);
glVertex2d(x, y + 1);
glVertex2d(x + 1, y + 1);
glVertex2d(x + 1, y);
}
glEnd();
}
void DisplayVRAM(void)
{
for (int x = 0; x < SCREEN_WIDTH; x++)
{
for (int y = 0; y < SCREEN_HEIGHT; y++)
{
(vram[(y * SCREEN_WIDTH_BYTE) + (x >> 3)] & (128 >> (x & 7))) ? DrawPixel(x, y) : ClearPixel(x, y);
}
}
glFlush();
glfwSwapBuffers(win);
if (glfwWindowShouldClose(win))
{
glfwDestroyWindow(win);
exit(0);
}
}
fx::String io_buffer;
fx::String calc_buffer;
void printchar(int c)
{
calc_buffer.append((char)c);
}
void
printstr(char *s)
{
calc_buffer.append(s);
}
int main()
{
fx::Console console(vram);
Init();
const char *help_str[] =
{
"F1: ABS",
"F2: DEF",
"F3: FRA",
"F4: INT",
"F5: LOG",
"F6: POW",
"F7: PRO",
"F8: ROO",
"F9: SQR",
"F10: STR",
"F11: SUM",
NULL
};
for (int i = 0; help_str[i] != NULL; i++)
{
std::cout << help_str[i] << "\t";
}
std::cout << std::endl;
while (true)
{
console.input(io_buffer);
calc_buffer.clear();
printf("io_buffer.c_str() = %s\n", io_buffer.c_str());
run((char *)io_buffer.c_str());
if (calc_buffer.c_str()[calc_buffer.size() - 1] == '\n')
{
calc_buffer.backspace();
}
console.output(calc_buffer);
}
}