-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.cpp
85 lines (65 loc) · 1.94 KB
/
hello.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
asm(R"(
.code16gcc
call _dosmain
mov $0x4C,%ah
int $0x21
)");
#include "dos.h"
namespace {
#include "mode13.h"
#include "pipomath.h"
template <int W, int H, class T>
void computeFx(unsigned char *const screen, const T &f) {
for (int y = H, o = 0; y; --y) {
for (int x = W; x; --x) {
screen[o++] = f(x, y);
}
}
}
template <class T, int W, int H, typename F> T *initBuffer(const F &f) {
T *buffer = (T *)allocBuffer(W * H * sizeof(T));
for (int y = 0, o = 0; y < H; ++y) {
for (int x = 0; x < W; ++x) {
buffer[o++] = f(x, y);
}
}
return buffer;
}
} // namespace
extern "C" int dosmain(void) {
const unsigned short ds = getDs();
allocBuffer(1 << 16);
unsigned char *const screen = ((unsigned char *)0xa0000) - (16 * ds);
unsigned char *const buffer = allocBuffer(320 * 200);
setMode(0x13);
fill(screen, 0, 320 * 200);
unsigned char *const lutSin = initBuffer<unsigned char, 256, 1>(
[](int x, int) { return fakesini<int>(x, 256); });
unsigned char *const map = initBuffer<unsigned char, 256, 256>(
[=](int x, int y) { return lutSin[x] + lutSin[y]; });
setPalette([=](int i, int &r, int &g, int &b) {
r = 63 - lutSin[i] / 2;
b = lutSin[i] / 4;
g = i / 4;
});
auto *const target = buffer;
for (unsigned int j = 0, jx = 0, jy = 0; j < 1000;
++j, jx += 7 * 64, jy += 9 * 64) {
const int c0x = 160 - 128 + 2 * lutSin[(jx / 256) & 255];
const int c0y = 100;
const int c1x = 160;
const int c1y = 100 - 64 + lutSin[(jy / 256) & 255];
computeFx<320, 200>(target, [=](int x, int y) -> unsigned char {
const int d0 = (lengthSq(c0x - x, c0y - y) >> 7) & 0xff;
const int d1 = (lengthSq(c1x - x, c1y - y) >> 7) & 0xff;
const unsigned char r = map[(d0 << 8) | d1];
return r;
});
if (target != screen)
blit(screen, target, 320 * 200);
}
fill(screen, 0, 320 * 200);
setMode(0x3);
print("Hello, World!\n$");
return 0;
}