many things, cosmo build!
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#ifndef PLR_DISPLAY_H
|
||||
#define PLR_DISPLAY_H
|
||||
|
||||
__attribute__((used)) extern int plr_display_x11_main(int argc, char *argv[]);
|
||||
__attribute__((used)) extern int plr_display_x11_main(int argc,
|
||||
char const *const *argv);
|
||||
__attribute__((used)) extern int plr_display_dos_main(void);
|
||||
|
||||
#endif
|
||||
|
||||
+190
-111
@@ -1,6 +1,3 @@
|
||||
#include <X11/X.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
@@ -11,16 +8,26 @@
|
||||
#include "../../Common/bits.h"
|
||||
#include "../../Common/buf.h"
|
||||
#include "../../Common/cfg.h"
|
||||
#include "../../Common/def.h"
|
||||
#include "../../Common/lzw.h"
|
||||
#include "../../Common/mat.h"
|
||||
#include "../../Common/std.h"
|
||||
#include "../../Common/str.h"
|
||||
#include "../../Common/test.h"
|
||||
#include "../draw.h"
|
||||
#include "display.h"
|
||||
|
||||
/* https://hereket.com/posts/from-scratch-x11-windowing/ */
|
||||
/* https://gaultier.github.io/blog/write_a_video_game_from_scratch_like_1987.html
|
||||
*/
|
||||
#if COM_DEF_TARGET == COM_DEF_TARGET_COSMO
|
||||
#include <X.h>
|
||||
#else
|
||||
#include <X11/X.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
https://hereket.com/posts/from-scratch-x11-windowing/
|
||||
https://gaultier.github.io/blog/write_a_video_game_from_scratch_like_1987.html
|
||||
https://xorg.freedesktop.org/archive/X11R7.7-RC1/doc/xproto/x11protocol.html
|
||||
*/
|
||||
|
||||
static struct {
|
||||
uint32_t id;
|
||||
@@ -94,7 +101,7 @@ static struct plr_x11_auth_entry {
|
||||
result.success = true;
|
||||
return result;
|
||||
BREAK:
|
||||
com_std_printf("Failure to initialize X11\n");
|
||||
com_std_print('c', "Failure to initialize X11");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -108,8 +115,8 @@ static bool plr_x11_handshake(com_std_fd xfd,
|
||||
uint16_t auth_len;
|
||||
uint16_t auth_data_len;
|
||||
uint16_t pad1;
|
||||
} request = {
|
||||
.endianness = 'l',
|
||||
} __attribute__((packed)) request = {
|
||||
.endianness = COM_DEF_CPU_LITEND ? 'l' : 'B',
|
||||
.major_version = 11,
|
||||
.auth_len = sizeof(AUTH_ENTRY_MAGIC_COOKIE) - 1, // IS -1 NEEDED?
|
||||
.auth_data_len = auth_entry.auth_data->len,
|
||||
@@ -131,7 +138,7 @@ static bool plr_x11_handshake(com_std_fd xfd,
|
||||
uint16_t major_version;
|
||||
uint16_t minor_version;
|
||||
uint16_t length;
|
||||
} response;
|
||||
} __attribute__((packed)) response;
|
||||
|
||||
if (!com_std_read(xfd, &response, sizeof response))
|
||||
return false;
|
||||
@@ -154,7 +161,7 @@ static bool plr_x11_handshake(com_std_fd xfd,
|
||||
uint8_t min_keycode;
|
||||
uint8_t max_keycode;
|
||||
uint32_t pad2;
|
||||
} dyn_response;
|
||||
} __attribute__((packed)) dyn_response;
|
||||
|
||||
if (!com_std_read(xfd, &dyn_response, sizeof dyn_response))
|
||||
return false;
|
||||
@@ -177,6 +184,54 @@ static bool plr_x11_handshake(com_std_fd xfd,
|
||||
return true;
|
||||
}
|
||||
|
||||
/* TODO: Instead have a poll_events function instead. */
|
||||
static inline bool plr_x11_poll_errors(com_std_fd xfd) {
|
||||
union {
|
||||
struct {
|
||||
uint8_t type;
|
||||
uint8_t errcode;
|
||||
uint16_t sequenceid;
|
||||
uint32_t badval;
|
||||
uint16_t minorop;
|
||||
uint32_t majorop;
|
||||
char pad[18];
|
||||
} __attribute__((packed)) error;
|
||||
struct {
|
||||
uint8_t type;
|
||||
uint8_t data;
|
||||
uint16_t sequenceid;
|
||||
uint32_t length;
|
||||
char pad[24];
|
||||
} __attribute__((packed)) reply;
|
||||
} response;
|
||||
|
||||
while (com_std_has_data(xfd)) {
|
||||
if (!com_std_read(xfd, &response, sizeof response))
|
||||
return false;
|
||||
|
||||
/* Exhaust variable length data of reply. */
|
||||
if (response.reply.type == 1) {
|
||||
char buf[1024];
|
||||
com_std_assert(response.reply.length * 4 <= sizeof buf);
|
||||
if (!com_std_read(xfd, &buf, response.reply.length * 4))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (response.reply.type == 0 && response.error.errcode != 0) {
|
||||
com_std_print('c', "X11 error code=", 'u', response.error.errcode, 'c',
|
||||
" for seqid=", 'u', response.error.sequenceid);
|
||||
|
||||
/* This means X11 closed the connection. */
|
||||
// if (response.error.errcode == 0)
|
||||
// return false;
|
||||
}
|
||||
|
||||
/* TODO: Save polled events, as they might be used later. */
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline uint32_t plr_x11_next_id(void) {
|
||||
static uint32_t cur_id = 0;
|
||||
cur_id = 1 + ((plr_x11_connection.resource_id_mask & (cur_id)) |
|
||||
@@ -184,29 +239,35 @@ static inline uint32_t plr_x11_next_id(void) {
|
||||
return cur_id;
|
||||
}
|
||||
|
||||
/* Used to number requests. */
|
||||
static inline uint32_t plr_x11_next_seqid(void) {
|
||||
static uint32_t cur_id = 1;
|
||||
return cur_id++;
|
||||
}
|
||||
|
||||
static uint32_t plr_x11_create_graphical_context(com_std_fd xfd) {
|
||||
uint32_t const gc_id = plr_x11_next_id();
|
||||
uint32_t const seq = plr_x11_next_seqid();
|
||||
struct {
|
||||
uint8_t opcode;
|
||||
uint8_t pad1;
|
||||
uint16_t length;
|
||||
uint16_t request_length;
|
||||
uint32_t id;
|
||||
uint32_t drawable;
|
||||
uint32_t bitmask;
|
||||
uint32_t value1;
|
||||
} request = {
|
||||
} __attribute__((packed)) request = {
|
||||
.opcode = 55,
|
||||
.length = 5,
|
||||
.request_length = sizeof request / 4,
|
||||
.id = gc_id,
|
||||
.drawable = plr_x11_root_screen.id,
|
||||
.bitmask = 8, /* TODO: Figure out. */
|
||||
.value1 = 0x0000ff00,
|
||||
.value1 = 0x00000000,
|
||||
};
|
||||
|
||||
if (com_std_write(xfd, &request, sizeof request))
|
||||
return gc_id;
|
||||
else
|
||||
if (!com_std_write(xfd, &request, sizeof request))
|
||||
return 0;
|
||||
return gc_id;
|
||||
}
|
||||
|
||||
static uint32_t plr_x11_create_window(com_std_fd xfd) {
|
||||
@@ -220,6 +281,7 @@ static uint32_t plr_x11_create_window(com_std_fd xfd) {
|
||||
#define EVENT_FLAG_BUTTON_RELEASE 0x8
|
||||
|
||||
uint32_t const window_id = plr_x11_next_id();
|
||||
uint32_t const seq = plr_x11_next_seqid();
|
||||
struct {
|
||||
uint8_t opcode;
|
||||
uint8_t depth;
|
||||
@@ -236,10 +298,10 @@ static uint32_t plr_x11_create_window(com_std_fd xfd) {
|
||||
uint32_t bitmask;
|
||||
uint32_t value1;
|
||||
uint32_t value2;
|
||||
} request = {
|
||||
} __attribute__((packed)) request = {
|
||||
.opcode = 1,
|
||||
.depth = 32,
|
||||
.request_length = 8 + 2,
|
||||
.depth = COM_CFG_COLORS * 8,
|
||||
.request_length = sizeof request / 4,
|
||||
.window_id = window_id,
|
||||
.parent_id = plr_x11_root_screen.id,
|
||||
.width = COM_CFG_WIDTH,
|
||||
@@ -248,16 +310,15 @@ static uint32_t plr_x11_create_window(com_std_fd xfd) {
|
||||
.class = 1,
|
||||
.root_visual_id = plr_x11_root_screen.root_visual_id,
|
||||
.bitmask = FLAG_WIN_BG_PIXEL | FLAG_WIN_EVENT,
|
||||
.value1 = 0x00ffff00,
|
||||
.value1 = 0x00000000,
|
||||
.value2 = EVENT_FLAG_EXPOSURE | EVENT_FLAG_BUTTON_RELEASE |
|
||||
EVENT_FLAG_BUTTON_PRESS | EVENT_FLAG_KEY_PRESS |
|
||||
EVENT_FLAG_KEY_RELEASE,
|
||||
};
|
||||
|
||||
if (com_std_write(xfd, &request, sizeof request))
|
||||
return window_id;
|
||||
else
|
||||
if (!com_std_write(xfd, &request, sizeof request))
|
||||
return 0;
|
||||
return window_id;
|
||||
}
|
||||
|
||||
static bool plr_x11_show_window(com_std_fd xfd, uint32_t window_id) {
|
||||
@@ -266,9 +327,9 @@ static bool plr_x11_show_window(com_std_fd xfd, uint32_t window_id) {
|
||||
uint8_t pad1;
|
||||
uint16_t request_length;
|
||||
uint32_t window_id;
|
||||
} request = {
|
||||
} __attribute__((packed)) request = {
|
||||
.opcode = 8,
|
||||
.request_length = 2,
|
||||
.request_length = sizeof request / 4,
|
||||
.window_id = window_id,
|
||||
};
|
||||
return com_std_write(xfd, &request, sizeof request);
|
||||
@@ -276,36 +337,35 @@ static bool plr_x11_show_window(com_std_fd xfd, uint32_t window_id) {
|
||||
|
||||
static uint32_t plr_x11_create_pixmap(com_std_fd xfd, uint32_t window_id) {
|
||||
uint32_t const pixmap_id = plr_x11_next_id();
|
||||
uint32_t const seq = plr_x11_next_seqid();
|
||||
struct {
|
||||
uint8_t opcode;
|
||||
uint8_t depth;
|
||||
uint16_t length;
|
||||
uint16_t request_length;
|
||||
uint32_t pixmap_id;
|
||||
uint32_t drawable;
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
} request = {
|
||||
} __attribute__((packed)) request = {
|
||||
.opcode = 53,
|
||||
.depth = 32,
|
||||
.length = 4,
|
||||
.depth = COM_CFG_COLORS * 8,
|
||||
.request_length = sizeof request / 4,
|
||||
.pixmap_id = pixmap_id,
|
||||
.drawable = window_id,
|
||||
.width = COM_CFG_WIDTH,
|
||||
.height = COM_CFG_HEIGHT,
|
||||
};
|
||||
|
||||
if (com_std_write(xfd, &request, sizeof request))
|
||||
return pixmap_id;
|
||||
else
|
||||
if (!com_std_write(xfd, &request, sizeof request))
|
||||
return 0;
|
||||
return pixmap_id;
|
||||
}
|
||||
|
||||
static bool
|
||||
plr_x11_put_framebuffer(com_std_fd xfd, uint32_t gc_id, uint32_t window_id,
|
||||
uint32_t pixmap_id,
|
||||
uint32_t pixels[COM_CFG_WIDTH * COM_CFG_HEIGHT]) {
|
||||
uint32_t const padded =
|
||||
com_bits_nalign(4 * COM_CFG_WIDTH * COM_CFG_HEIGHT, 4);
|
||||
static bool plr_x11_put_framebuffer(com_std_fd xfd, uint32_t gc_id,
|
||||
uint32_t pixmap_id,
|
||||
uint8_t pixels[COM_CFG_FBSIZE]) {
|
||||
uint32_t const seq = plr_x11_next_seqid();
|
||||
uint32_t const padded = com_bits_nalign(COM_CFG_FBSIZE, 4);
|
||||
|
||||
struct {
|
||||
uint8_t opcode;
|
||||
@@ -320,35 +380,84 @@ plr_x11_put_framebuffer(com_std_fd xfd, uint32_t gc_id, uint32_t window_id,
|
||||
uint8_t left_pad;
|
||||
uint8_t depth;
|
||||
uint16_t pad1;
|
||||
} request = {
|
||||
} __attribute__((packed)) request = {
|
||||
.opcode = 72,
|
||||
.format = 2, // ZPixmap
|
||||
.request_length = 6 + padded / 4,
|
||||
.request_length = sizeof request / 4 + padded / 4,
|
||||
.drawable_id = pixmap_id,
|
||||
.gc_id = gc_id,
|
||||
.width = COM_CFG_WIDTH,
|
||||
.height = COM_CFG_HEIGHT,
|
||||
.dst_x = 0,
|
||||
.dst_y = 0,
|
||||
.depth = 32,
|
||||
.depth = COM_CFG_COLORS * 8,
|
||||
};
|
||||
|
||||
if (!com_std_write(xfd, &request, sizeof request))
|
||||
return false;
|
||||
if (!com_std_write(xfd, pixels, 4 * COM_CFG_WIDTH * COM_CFG_HEIGHT))
|
||||
if (!com_std_write(xfd, pixels, COM_CFG_FBSIZE))
|
||||
return false;
|
||||
/* Use request memory for pad, it doesn't matter what we write. */
|
||||
uint32_t const padfinal = padded - (4 * COM_CFG_WIDTH * COM_CFG_HEIGHT);
|
||||
if (padfinal && !com_std_write(xfd, &request, padfinal))
|
||||
uint32_t const padfinal = padded - COM_CFG_FBSIZE;
|
||||
if (padfinal && !com_std_write(xfd, &pixels, padfinal))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool plr_x11_establish_connection(com_std_fd xfd, int argc,
|
||||
char const *const *argv) {
|
||||
com_buf_make_on_stack(char, xauthbuf, 1024, 0);
|
||||
|
||||
/* First we need to authenticate X11 connection, which requires some funk.
|
||||
*/
|
||||
/* We assume that $XAUTHORITY is set and I hope it is true. */
|
||||
char const *xauthpath = NULL;
|
||||
for (char const *const *envp = &argv[argc + 1]; *envp != NULL; ++envp) {
|
||||
static const struct com_str xauthlit = com_str_lit("XAUTHORITY=");
|
||||
if (com_str_ext_prefixed(*envp, xauthlit)) {
|
||||
xauthpath = &((*envp)[xauthlit.len]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Open it and parse. */
|
||||
com_std_fd const xauthfd = com_std_open(xauthpath, COM_STD_OPEN_READ);
|
||||
if (xauthfd < 0) {
|
||||
com_std_print('c', "Failure to initialize X11");
|
||||
return false;
|
||||
}
|
||||
|
||||
struct com_bin xauthbin = {
|
||||
.ctx = (void *)(int64_t)xauthfd,
|
||||
.flags = COM_BIN_BIG_ENDIAN,
|
||||
.interface = {.readn = fileread, .skipn = fileskip}};
|
||||
|
||||
/* Loop over auth entries until we find magic cookie one. */
|
||||
struct plr_x11_auth_entry auth_entry;
|
||||
do {
|
||||
com_buf_clear(xauthbuf);
|
||||
auth_entry = plr_x11_read_auth_entry(&xauthbin, xauthbuf);
|
||||
} while (auth_entry.success && auth_entry.family != 256);
|
||||
if (!auth_entry.success) {
|
||||
com_std_print('c', "Failure to initialize X11");
|
||||
return false;
|
||||
}
|
||||
|
||||
com_std_close(xauthfd);
|
||||
|
||||
/* TODO: Check for auth_entry.name == MAGIC ? */
|
||||
if (!plr_x11_handshake(xfd, auth_entry)) {
|
||||
com_std_print('c', "Failure to initialize X11");
|
||||
return false;
|
||||
}
|
||||
|
||||
com_buf_free(xauthbuf);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static uint32_t pixel_buffer[COM_CFG_WIDTH * COM_CFG_HEIGHT];
|
||||
|
||||
// TODO: correct error handling.
|
||||
extern int plr_display_x11_main(int argc, char *argv[]) {
|
||||
extern int plr_display_x11_main(int argc, char const *const *argv) {
|
||||
char test_string[] = "what is this?";
|
||||
char *compressed_string = NULL;
|
||||
uint32_t compressed_string_sz = 0;
|
||||
@@ -366,12 +475,16 @@ extern int plr_display_x11_main(int argc, char *argv[]) {
|
||||
|
||||
com_mat_t t0 = com_mat_mul(m1, m0);
|
||||
com_mat_t t1 = com_mat_mul_reodered(com_mat_reoder(m1), m0);
|
||||
com_fix_print(t0.a[4]);
|
||||
com_fix_print(t1.a[4]);
|
||||
com_std_print('f', t0.a[4]);
|
||||
com_std_print('f', t1.a[4]);
|
||||
|
||||
// com_vec_t v0 = com_mat_vec_project(com_mat_reoder(m0), com_vec_identity());
|
||||
// com_fix_print(v0.a[0]);
|
||||
|
||||
#ifndef NDEBUG
|
||||
com_test_run();
|
||||
#endif
|
||||
|
||||
// com_fix_run_tests();
|
||||
// com_fix_run_bench();
|
||||
// com_mat_run_bench();
|
||||
@@ -380,87 +493,47 @@ extern int plr_display_x11_main(int argc, char *argv[]) {
|
||||
/* Open X11 socket for communication. */
|
||||
com_std_fd const xfd = com_std_socket(false);
|
||||
if (!xfd) {
|
||||
com_std_printf("Failure to initialize X11\n");
|
||||
com_std_print('c', "Failure to initialize X11");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!com_std_connect(xfd, false, "/tmp/.X11-unix/X0")) {
|
||||
com_std_printf("Failure to initialize X11\n");
|
||||
com_std_print('c', "Failure to initialize X11");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* First we need to authenticate X11 connection, which requires some funk. */
|
||||
/* We assume that $XAUTHORITY is set and I hope it is true. */
|
||||
char const *xauthpath = NULL;
|
||||
for (char **envp = &argv[argc + 1]; *envp != NULL; ++envp) {
|
||||
static const struct com_str xauthlit = com_str_lit("XAUTHORITY=");
|
||||
if (com_str_ext_prefixed(*envp, xauthlit)) {
|
||||
xauthpath = &((*envp)[xauthlit.len]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Open it and parse. */
|
||||
com_std_fd const xauthfd = com_std_open(xauthpath, COM_STD_OPEN_READ);
|
||||
if (xauthfd < 0) {
|
||||
com_std_printf("Failure to initialize X11\n");
|
||||
if (!plr_x11_establish_connection(xfd, argc, argv)) {
|
||||
com_std_print('c', "Failure to initialize X11");
|
||||
return -1;
|
||||
}
|
||||
|
||||
com_buf_make_on_stack(char, xauthbuf, 1024, 0);
|
||||
struct com_bin xauthbin = {
|
||||
.ctx = (void *)(int64_t)xauthfd,
|
||||
.flags = COM_BIN_BIG_ENDIAN,
|
||||
.interface = {.readn = fileread, .skipn = fileskip}};
|
||||
|
||||
/* Loop over auth entries until we find magic cookie one. */
|
||||
struct plr_x11_auth_entry auth_entry;
|
||||
do {
|
||||
com_buf_clear(xauthbuf);
|
||||
auth_entry = plr_x11_read_auth_entry(&xauthbin, xauthbuf);
|
||||
} while (auth_entry.success && auth_entry.family != 256);
|
||||
if (!auth_entry.success) {
|
||||
com_std_printf("Failure to initialize X11\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
com_std_close(xauthfd);
|
||||
|
||||
/* TODO: Check for auth_entry.name == MAGIC ? */
|
||||
if (!plr_x11_handshake(xfd, auth_entry)) {
|
||||
com_std_printf("Failure to initialize X11\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
com_buf_free(xauthbuf);
|
||||
|
||||
uint32_t const gc = plr_x11_create_graphical_context(xfd);
|
||||
if (!gc) {
|
||||
com_std_printf("Failure to initialize X11\n");
|
||||
com_std_print('c', "Failure to initialize X11");
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t const win = plr_x11_create_window(xfd);
|
||||
if (!win) {
|
||||
com_std_printf("Failure to initialize X11\n");
|
||||
com_std_print('c', "Failure to initialize X11");
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t const fb = plr_x11_create_pixmap(xfd, win);
|
||||
if (!fb) {
|
||||
com_std_printf("Failure to initialize X11\n");
|
||||
com_std_print('c', "Failure to initialize X11");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Display *display = XOpenDisplay(NULL);
|
||||
// if (NULL == display) {
|
||||
// com_std_printf("Failed to initialize display");
|
||||
// com_std_print('c', "Failed to initialize display");
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
// Window root = DefaultRootWindow(display);
|
||||
// if (None == root) {
|
||||
// com_std_printf("No root window found");
|
||||
// com_std_print('c', "No root window found");
|
||||
// XCloseDisplay(display);
|
||||
// return -1;
|
||||
// }
|
||||
@@ -473,7 +546,7 @@ extern int plr_display_x11_main(int argc, char *argv[]) {
|
||||
// XCreateSimpleWindow(display, root, 0, 0, WIDTH, HEIGHT, 0, 0,
|
||||
// 0xffffffff);
|
||||
// if (None == window) {
|
||||
// com_std_printf("Failed to create window");
|
||||
// com_std_print('c', "Failed to create window");
|
||||
// XCloseDisplay(display);
|
||||
// return -1;
|
||||
// }
|
||||
@@ -507,7 +580,7 @@ extern int plr_display_x11_main(int argc, char *argv[]) {
|
||||
// pixel_buffer, WIDTH, HEIGHT, 32, 0);
|
||||
|
||||
// if (!ximage) {
|
||||
// com_std_printf("Failed to create XImage\n");
|
||||
// com_std_print('c', "Failed to create XImage");
|
||||
// // com_std_alloc(pixel_buffer, 0);
|
||||
// XCloseDisplay(display);
|
||||
// return -1;
|
||||
@@ -547,16 +620,22 @@ extern int plr_display_x11_main(int argc, char *argv[]) {
|
||||
|
||||
// XCloseDisplay(display);
|
||||
|
||||
uint8_t *fbm = plr_draw_get_pixel_buffer();
|
||||
plr_draw_screen(fbm);
|
||||
|
||||
// if (!plr_x11_put_framebuffer(xfd, gc, fb, fbm)) {
|
||||
// com_std_print('c', "Failure to drive X11");
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
if (!plr_x11_show_window(xfd, win)) {
|
||||
com_std_print('c', "Failure to drive X11");
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
plr_draw_screen((uint8_t *)pixel_buffer);
|
||||
|
||||
if (!plr_x11_put_framebuffer(xfd, gc, win, fb, pixel_buffer)) {
|
||||
com_std_printf("Failure to drive X11\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!plr_x11_show_window(xfd, win)) {
|
||||
com_std_printf("Failure to drive X11\n");
|
||||
if (!plr_x11_poll_errors(xfd)) {
|
||||
com_std_print('c', "X11 closed connection");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "../../Common/std.h"
|
||||
#include "../Display/display.h"
|
||||
#include <stdio.h>
|
||||
extern int main(int argc, char const *const *argv) {
|
||||
com_std_write(COM_STD_OUTFD, "TEST?", sizeof "TEST?" - 1);
|
||||
return plr_display_x11_main(argc, argv);
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
#include "../Display/display.h"
|
||||
|
||||
extern int main(int argc, char **argv) { plr_display_x11_main(argc, argv); }
|
||||
+28
-21
@@ -4,7 +4,15 @@ DEBUG ?= 1 # Emit debug info.
|
||||
SQUEEZE ?= 0 # Nuclear option to save space.
|
||||
BITS ?= 64
|
||||
RUN ?= 0
|
||||
CFLAGS = -Wall -std=gnu99 -flto=thin -ffast-math -fno-ident -fvisibility=hidden -fuse-ld=lld
|
||||
|
||||
ISCLANG = 1
|
||||
ifeq ($(MAKECMDGOALS),cosmo)
|
||||
ISCLANG = 0
|
||||
endif
|
||||
CFLAGS = -Wall -std=gnu99 -ffast-math -fno-ident -fvisibility=hidden
|
||||
ifeq ($(ISCLANG), 1)
|
||||
CFLAGS = -flto=thin -fuse-ld=lld
|
||||
endif
|
||||
ifeq ($(MAKECMDGOALS),linux)
|
||||
CFLAGS += -fno-pic -fno-pie
|
||||
ifeq ($(RELEASE), 1)
|
||||
@@ -12,7 +20,10 @@ ifeq ($(MAKECMDGOALS),linux)
|
||||
-Wl,--optimize-bb-jumps
|
||||
endif
|
||||
ifeq ($(SQUEEZE), 1)
|
||||
CFLAGS += -Wl,-T,tiny.ld -Wl,--icf=all -Wl,--bp-compression-sort=both \
|
||||
ifeq ($(DEBUG), 0)
|
||||
CFLAGS += -Wl,-T,tiny.ld
|
||||
endif
|
||||
CFLAGS += -Wl,--icf=all -Wl,--bp-compression-sort=both \
|
||||
-Wl,--nmagic
|
||||
endif
|
||||
ifeq ($(BITS), 64)
|
||||
@@ -37,32 +48,27 @@ ifeq ($(RELEASE), 1)
|
||||
-Wl,-mllvm,--vectorize-slp=true \
|
||||
-Wl,-mllvm,--enable-gvn-hoist=true
|
||||
endif
|
||||
# TODO: Just use amalgam build for all?
|
||||
DEPS = ../Common/lzw.h ../Common/mat.h ../Common/vec.h ../Common/fix.h ../Common/def.h ../Common/bits.h \
|
||||
../Common/gem.h \
|
||||
../Common/Timer/time.h \
|
||||
./Display/display.h \
|
||||
./draw.h
|
||||
SRC = ../Common/lzw.c ../Common/fix.c ../Common/mat.c ./draw.c
|
||||
LINUX = ./amalgam.c
|
||||
WASM = ./amalgam.c
|
||||
DOS = maindos.c Display/dos.c
|
||||
|
||||
%.o: %.c $(DEPS)
|
||||
$(CC) -c -o $@ $< $(CFLAGS)
|
||||
|
||||
%.o: %.s $(DEPS)
|
||||
$(CC) -c -o $@ $< $(CFLAGS)
|
||||
|
||||
# TODO: Make it work with no stdlib.
|
||||
linux: CFLAGS += -static -mbmi2 -nostdlib
|
||||
linux: $(LINUX) | $(SRC)
|
||||
linux: ./amalgam.c
|
||||
$(CC) -o player $^ $(CFLAGS)
|
||||
|
||||
# Note: lld package might need to be downloaded.
|
||||
wasm: CFLAGS += --target=wasm32 -nostdlib -Wl,--no-entry -msimd128 -mbulk-memory
|
||||
wasm:
|
||||
$(CC) -o player.wasm $(WASM) $(CFLAGS)
|
||||
$(CC) -o player.wasm ./amalgam.c $(CFLAGS)
|
||||
|
||||
# todo: Add -mtiny for release without debug
|
||||
cosmo: CC = ./Cosmo/bin/cosmocc -I /usr/include/X11 -mdbg
|
||||
cosmo: ./amalgam.c
|
||||
$(CC) -o ./Out/Cosmo/player $^
|
||||
ifeq ($(RUN), 1)
|
||||
ifeq ($(DEBUG), 1)
|
||||
gdb ./Out/Cosmo/player.com.dbg
|
||||
else
|
||||
./Out/Cosmo/player
|
||||
endif
|
||||
endif
|
||||
|
||||
# https://tippach.hier-im-netz.de/wdosx
|
||||
dos: CFLAGS += -ffreestanding -m32 -fno-PIC -fno-PIE -nostdlib -nodefaultlibs
|
||||
@@ -79,5 +85,6 @@ else
|
||||
dosbox -c "mount c $(PWD)" -c "c:" -c "DOS.EXE"
|
||||
endif
|
||||
endif
|
||||
|
||||
clean:
|
||||
rm -r *.o ../*.o
|
||||
|
||||
Executable
BIN
Binary file not shown.
Executable
+8
@@ -0,0 +1,8 @@
|
||||
:;# amalgam of batch and shell scripts as a entry single point
|
||||
|
||||
:; SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
:; $SCRIPT_DIR/ape $SCRIPT_DIR/player
|
||||
:; exit
|
||||
|
||||
@echo off
|
||||
player
|
||||
+5
-1
@@ -21,8 +21,12 @@
|
||||
#endif
|
||||
#include "../Common/Timer/stub.c"
|
||||
#include "./Display/x11.c"
|
||||
// #include "./Main/libc.c"
|
||||
#elif COM_DEF_TARGET == COM_DEF_TARGET_WASM
|
||||
#include "../Common/Std/stub.c"
|
||||
#include "../Common/Timer/stub.c"
|
||||
#elif COM_DEF_TARGET == COM_DEF_TARGET_COSMO
|
||||
#include "../Common/Std/libc.c"
|
||||
#include "../Common/Timer/posix.c"
|
||||
#include "./Display/x11.c"
|
||||
#include "./Main/cosmo.c"
|
||||
#endif
|
||||
|
||||
+10
-10
@@ -2,30 +2,30 @@
|
||||
#include "../Common/cfg.h"
|
||||
#include "../Common/def.h"
|
||||
#include "../Common/gem.h"
|
||||
#include "../Common/std.h"
|
||||
#include "../Common/time.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#if COM_DEF_TARGET == COM_DEF_TARGET_WASM
|
||||
uint8_t plr_draw_buffer[COM_CFG_WIDTH * COM_CFG_HEIGHT * 4];
|
||||
static _Alignas(16) uint8_t plr_draw_buffer[COM_CFG_FBSIZE];
|
||||
|
||||
com_def_export_sym(
|
||||
"plr_draw_get_pixel_buffer") uint8_t *plr_draw_get_pixel_buffer(void) {
|
||||
return plr_draw_buffer;
|
||||
}
|
||||
#endif
|
||||
|
||||
com_def_export_sym("plr_draw_screen") void plr_draw_screen(
|
||||
uint8_t *pixel_buffer) {
|
||||
uint8_t *pixel_buffer_aligned = __builtin_assume_aligned(pixel_buffer, 16);
|
||||
for (int y = 0; y < COM_CFG_HEIGHT; y++) {
|
||||
for (int x = 0; x < COM_CFG_WIDTH; x++) {
|
||||
int pixel_index = (y * COM_CFG_WIDTH + x) * 4;
|
||||
int pixel_index = (y * COM_CFG_WIDTH + x) * COM_CFG_COLORS;
|
||||
|
||||
// Assuming standard Little-Endian 32-bit BGRA format
|
||||
pixel_buffer[pixel_index + 0] = (x) % 256; // Blue
|
||||
pixel_buffer[pixel_index + 1] = (y) % 256; // Green
|
||||
pixel_buffer[pixel_index + 2] = (x + y) % 256; // Red
|
||||
pixel_buffer[pixel_index + 3] = 255; // Alpha/Padding
|
||||
pixel_buffer_aligned[pixel_index + 0] = (x) % 256; // Blue
|
||||
pixel_buffer_aligned[pixel_index + 1] = (y) % 256; // Green
|
||||
pixel_buffer_aligned[pixel_index + 2] = (x + y) % 256; // Red
|
||||
#if COM_CFG_COLORS == 4
|
||||
pixel_buffer_aligned[pixel_index + 3] = 255; // Alpha/Padding
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ com_def_export_sym("plr_draw_screen") void plr_draw_screen(
|
||||
// com_std_printf("%i, %i\n", p2.a[0], p2.a[1]);
|
||||
// com_std_printf("%i, %i\n", p3.a[0], p3.a[1]);
|
||||
|
||||
uint8_t tex[32 * 32 * 3] = {0};
|
||||
uint8_t _Alignas(16) tex[32 * 32 * 3] = {0};
|
||||
for (int y = 0; y < 32; ++y) {
|
||||
for (int x = 0; x < 32; ++x) {
|
||||
// uint32_t idx = com_zord_order(x, y);
|
||||
|
||||
@@ -4,5 +4,6 @@
|
||||
#include <stdint.h>
|
||||
|
||||
extern void plr_draw_screen(uint8_t *pixel_buffer);
|
||||
extern uint8_t *plr_draw_get_pixel_buffer(void);
|
||||
|
||||
#endif
|
||||
|
||||
+4
-4
@@ -14,19 +14,19 @@ SECTIONS
|
||||
*(.text*)
|
||||
}
|
||||
|
||||
.rodata : {
|
||||
.rodata ALIGN(16) : {
|
||||
*(.rodata*)
|
||||
}
|
||||
|
||||
.data : {
|
||||
.data ALIGN(16) : {
|
||||
*(.data*)
|
||||
}
|
||||
|
||||
.shstrtab : {
|
||||
.shstrtab ALIGN(16) : {
|
||||
*(.shstrtab*)
|
||||
}
|
||||
|
||||
.bss : {
|
||||
.bss ALIGN(16) : {
|
||||
*(.bss*)
|
||||
*(COMMON)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user