2022-06-10 01:48:15 +00:00
|
|
|
#if 0
|
|
|
|
/*─────────────────────────────────────────────────────────────────╗
|
|
|
|
│ To the extent possible under law, Justine Tunney has waived │
|
|
|
|
│ all copyright and related or neighboring rights to this file, │
|
|
|
|
│ as it is written in the following disclaimers: │
|
|
|
|
│ • http://unlicense.org/ │
|
|
|
|
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
|
|
|
╚─────────────────────────────────────────────────────────────────*/
|
|
|
|
#endif
|
2022-09-13 09:28:07 +00:00
|
|
|
#include "libc/calls/calls.h"
|
2022-09-13 09:14:10 +00:00
|
|
|
#include "libc/calls/termios.h"
|
|
|
|
#include "libc/isystem/unistd.h"
|
2022-09-13 09:28:07 +00:00
|
|
|
#include "libc/math.h"
|
2022-06-10 01:48:15 +00:00
|
|
|
#include "libc/stdio/stdio.h"
|
2022-09-13 09:28:07 +00:00
|
|
|
#include "libc/str/str.h"
|
2022-09-13 09:14:10 +00:00
|
|
|
#include "libc/sysv/consts/termios.h"
|
2022-06-10 01:48:15 +00:00
|
|
|
|
2023-05-13 05:42:57 +00:00
|
|
|
#ifdef __x86_64__
|
|
|
|
|
2022-09-13 09:28:07 +00:00
|
|
|
/**
|
|
|
|
* @fileoverview Bare Metal VGA TTY demo.
|
|
|
|
*
|
|
|
|
* This program can boot as an operating system. Try it out:
|
|
|
|
*
|
|
|
|
* make -j8 o//examples/vga.com
|
|
|
|
* qemu-system-x86_64 -hda o//examples/vga.com -serial stdio
|
|
|
|
*
|
|
|
|
* Please note that, by default, APE binaries only use the serial port
|
|
|
|
* for stdio. To get the VGA console as an added bonus:
|
|
|
|
*
|
2023-07-26 20:54:49 +00:00
|
|
|
* __static_yoink("vga_console");
|
2022-09-13 09:28:07 +00:00
|
|
|
*
|
|
|
|
* Should be added to the top of your main() program source file.
|
|
|
|
*/
|
|
|
|
|
2023-07-26 20:54:49 +00:00
|
|
|
__static_yoink("vga_console");
|
2022-09-07 01:41:08 +00:00
|
|
|
|
2022-06-10 01:48:15 +00:00
|
|
|
int main(int argc, char *argv[]) {
|
2022-06-14 09:12:32 +00:00
|
|
|
volatile long double x = -.5;
|
|
|
|
volatile long double y = 1.5;
|
2022-09-13 09:14:10 +00:00
|
|
|
struct termios tio;
|
2022-09-13 09:28:07 +00:00
|
|
|
char buf[16];
|
2022-09-13 09:14:10 +00:00
|
|
|
ssize_t res;
|
|
|
|
if (tcgetattr(0, &tio) != -1) {
|
|
|
|
tio.c_lflag &= ~(ECHO | ICANON);
|
|
|
|
tcsetattr(0, TCSANOW, &tio);
|
|
|
|
}
|
|
|
|
write(1, "\e[5n", 4);
|
|
|
|
res = read(0, buf, 4);
|
|
|
|
if (res != 4 || memcmp(buf, "\e[0n", 4) != 0) {
|
|
|
|
printf("res = %d?\n", res);
|
|
|
|
return -1;
|
|
|
|
}
|
2022-10-05 13:46:50 +00:00
|
|
|
printf("\e[92;44mHello World!\e[0m %.19Lg\n", atan2l(x, y));
|
2022-09-13 09:28:07 +00:00
|
|
|
|
|
|
|
// read/print loop so machine doesn't reset on metal
|
|
|
|
for (;;) {
|
|
|
|
if ((res = readansi(0, buf, 16)) > 0) {
|
2022-10-05 13:46:50 +00:00
|
|
|
printf("got \e[97m%`'.*s\e[0m\r\n", res, buf);
|
2022-09-13 09:28:07 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-10 01:48:15 +00:00
|
|
|
}
|
2023-05-13 05:42:57 +00:00
|
|
|
|
|
|
|
#endif /* __x86_64__ */
|