diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-12-08 16:31:24 +0100 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-12-08 17:00:23 +0100 |
| commit | 4da7a3e44d2bbd7b21ae05c7b6604748e7227227 (patch) | |
| tree | cbb81eed24dd2bed75998e4f8ffb803dd479a6df /src | |
| parent | de3532bd6b685c66015202a48d53e1b8fa4900f5 (diff) | |
| download | jancity-4da7a3e44d2bbd7b21ae05c7b6604748e7227227.tar.gz | |
wip2
Diffstat (limited to 'src')
| -rw-r--r-- | src/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | src/gui/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/gui/inc/gui/combo_box.h | 29 | ||||
| -rw-r--r-- | src/gui/src/button.c | 6 | ||||
| -rw-r--r-- | src/gui/src/button_sprite.c | 31 | ||||
| -rw-r--r-- | src/gui/src/combo_box.c | 43 | ||||
| -rw-r--r-- | src/input/privinc/input_private.h | 19 | ||||
| -rw-r--r-- | src/input/src/vkeyboard.c | 13 | ||||
| -rw-r--r-- | src/net/ps1/src/net.c | 5 | ||||
| -rw-r--r-- | src/net/win9x/src/serial.c | 17 | ||||
| -rw-r--r-- | src/packet/src/packet.c | 2 | ||||
| -rw-r--r-- | src/sfx/CMakeLists.txt | 18 | ||||
| -rw-r--r-- | src/transport/src/heap.c | 6 | ||||
| -rw-r--r-- | src/transport/src/transport.c | 34 | ||||
| -rw-r--r-- | src/transport/test/test.c | 16 |
15 files changed, 185 insertions, 59 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bb05f29..58cbbf1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,5 @@ # Avoid C11 since it is not supported by the i386-mingw32 toolchain. -set(cflags ${cflags} -Wall -g3 -ffunction-sections -fdata-sections -pedantic -std=c99) +set(cflags ${cflags} -Wall -g3 -ffunction-sections -fdata-sections -pedantic) set(components building @@ -41,6 +41,8 @@ target_link_libraries(${PROJECT_NAME} PRIVATE system menu) foreach(c ${components}) add_subdirectory("${c}") target_compile_options(${c} PUBLIC ${cflags}) + target_compile_features(${c} PUBLIC c_std_99) + set_target_properties(${c} PROPERTIES C_STANDARD 99 C_EXTENSIONS OFF) endforeach() foreach(i ${interfaces}) diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index bd5b004..5fa625f 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -1,6 +1,7 @@ add_library(gui "src/bar.c" "src/button.c" + "src/button_sprite.c" "src/button_type1.c" "src/checkbox.c" "src/container.c" diff --git a/src/gui/inc/gui/combo_box.h b/src/gui/inc/gui/combo_box.h new file mode 100644 index 0000000..dd2fdea --- /dev/null +++ b/src/gui/inc/gui/combo_box.h @@ -0,0 +1,29 @@ +#ifndef GUI_COMBO_BOX_H +#define GUI_COMBO_BOX_H + +#include <gui.h> +#include <gui/button.h> +#include <util.h> +#include <stddef.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct gui_combo_box +{ + struct gui_common common; + struct gui_button b; +}; + +UTIL_STATIC_ASSERT(!offsetof(struct gui_combo_box, common), + "unexpected offset for struct gui_combo_box"); + +void gui_combo_box_init(struct gui_combo_box *c, enum gui_button_type t); + +#ifdef __cplusplus +} +#endif + +#endif /* GUI_COMBO_BOX_H */ diff --git a/src/gui/src/button.c b/src/gui/src/button.c index cf49679..8f00ff2 100644 --- a/src/gui/src/button.c +++ b/src/gui/src/button.c @@ -14,7 +14,7 @@ static int render(const struct gui_common *const g) static int (*const f[])(const struct gui_button *) = { [GUI_BUTTON_TYPE_1] = gui_button_render_type1, - /* [GUI_BUTTON_TYPE_SPRITE] = gui_button_render_sprite */ + [GUI_BUTTON_TYPE_SPRITE] = gui_button_render_sprite }; const struct gui_button *const b = (const struct gui_button *)g; @@ -28,7 +28,7 @@ static void get_dim(const struct gui_common *const g, static void (*const f[])(const struct gui_button *, short *, short *) = { [GUI_BUTTON_TYPE_1] = gui_button_get_dim_type1, - /* [GUI_BUTTON_TYPE_SPRITE] = gui_button_get_dim_sprite */ + [GUI_BUTTON_TYPE_SPRITE] = gui_button_get_dim_sprite }; const struct gui_button *const b = (const struct gui_button *)g; @@ -81,7 +81,7 @@ void gui_button_init(struct gui_button *const b, const enum gui_button_type t) static void (*const f[])(struct gui_button *) = { [GUI_BUTTON_TYPE_1] = gui_button_init_type1, - /* [GUI_BUTTON_TYPE_SPRITE] = gui_button_get_dim_sprite */ + [GUI_BUTTON_TYPE_SPRITE] = gui_button_get_dim_sprite }; f[b->type](b); diff --git a/src/gui/src/button_sprite.c b/src/gui/src/button_sprite.c new file mode 100644 index 0000000..5bdc1b0 --- /dev/null +++ b/src/gui/src/button_sprite.c @@ -0,0 +1,31 @@ +#include <gui.h> +#include <gui/button.h> +#include <gui_private.h> +#include <gui_button_private.h> +#include <gfx.h> +#include <stdio.h> + +int gui_button_render_sprite(const struct gui_button *const b) +{ + sprite_get_or_ret(s, -1); + + if (sprite_clone(b->u.sprite.s, s)) + return -1; + + gui_coords(&b->common, &s->x, &s->y); + sprite_sort(s); + return 0; +} + +void gui_button_get_dim_sprite(const struct gui_button *const b, + short *const w, short *const h) +{ + const struct sprite *const s = b->u.sprite.s; + + *w = s->w; + *h = s->h; +} + +void gui_button_init_sprite(struct gui_button *const b) +{ +} diff --git a/src/gui/src/combo_box.c b/src/gui/src/combo_box.c new file mode 100644 index 0000000..746b4d0 --- /dev/null +++ b/src/gui/src/combo_box.c @@ -0,0 +1,43 @@ +#include <gui/combo_box.h> +#include <gui.h> +#include <input.h> +#include <peripheral.h> +#include <camera.h> + +static int update(struct gui_common *const g, + const union peripheral *const p, const struct camera *const cam, + struct input *const in) +{ + return -1; +} + +static int render(const struct gui_common *const g) +{ + return -1; +} + +static void on_pressed(void *const arg) +{ +} + +void gui_combo_box_init(struct gui_combo_box *const c, + const enum gui_button_type t) +{ + static const struct gui_common_cb cb = + { + .update = update, + .render = render + }; + + *c = (const struct gui_combo_box) + { + .common = + { + .cb = &cb + } + }; + + gui_button_init(&c->b, t); + c->b.on_pressed = on_pressed; + gui_add_child(&c->common, &c->b.common); +} diff --git a/src/input/privinc/input_private.h b/src/input/privinc/input_private.h new file mode 100644 index 0000000..2305c12 --- /dev/null +++ b/src/input/privinc/input_private.h @@ -0,0 +1,19 @@ +#ifndef INPUT_PRIVATE_H +#define INPUT_PRIVATE_H + +#include <input.h> +#include <stdbool.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +bool input_vkeyboard_available(void); +int input_vkeyboard_show(void); + +#ifdef __cplusplus +} +#endif + +#endif /* INPUT_PRIVATE_H */ diff --git a/src/input/src/vkeyboard.c b/src/input/src/vkeyboard.c new file mode 100644 index 0000000..17e13a0 --- /dev/null +++ b/src/input/src/vkeyboard.c @@ -0,0 +1,13 @@ +#include <input.h> +#include <input_private.h> +#include <stdbool.h> + +bool input_vkeyboard_available(void) +{ + return false; +} + +int input_vkeyboard_show(void) +{ + return -1; +} diff --git a/src/net/ps1/src/net.c b/src/net/ps1/src/net.c index af964cf..185d990 100644 --- a/src/net/ps1/src/net.c +++ b/src/net/ps1/src/net.c @@ -7,6 +7,7 @@ #include <stdbool.h> #include <stddef.h> #include <stdio.h> +#include <stdint.h> static struct net_host { @@ -82,7 +83,7 @@ static int on_write(const void *const buf, size_t n, void *const arg) EnterCriticalSection(); - for (const char *b = buf; n; n--, b++) + for (const uint8_t *b = buf; n; n--, b++) { struct net_host_fifo *const f = &h->out; size_t new = f->pending + 1; @@ -115,7 +116,7 @@ static int on_read(void *const buf, const size_t n, void *const arg) EnterCriticalSection(); - for (char *b = buf; rem; rem--, b++) + for (uint8_t *b = buf; rem; rem--, b++) { if (f->read == f->pending) goto end; diff --git a/src/net/win9x/src/serial.c b/src/net/win9x/src/serial.c index c1cffb6..57d7261 100644 --- a/src/net/win9x/src/serial.c +++ b/src/net/win9x/src/serial.c @@ -1,6 +1,7 @@ #include <net.h> #include <net_private.h> #include <windows.h> +#include <ctype.h> #include <errno.h> #include <stddef.h> #include <stdio.h> @@ -244,6 +245,22 @@ static int on_write(const void *const buf, const size_t n, void *const arg) __func__, GetLastError()); goto failure; } + + printf("%s: outgoing packet, buf: %p, n: %u: [", __func__, buf, (unsigned)n); + + for (size_t i = 0; i < n; i++) + { + const char b = ((const char *)buf)[i]; + printf("%02hhx", b); + + if (isprint((unsigned char)b)) + printf(" (%c)", b); + + if (i + 1 < n) + printf(", "); + } + + printf("]\n"); } return get_result(h, r); diff --git a/src/packet/src/packet.c b/src/packet/src/packet.c index 3ace4af..eabda8b 100644 --- a/src/packet/src/packet.c +++ b/src/packet/src/packet.c @@ -79,7 +79,7 @@ static int read_header(struct packet_input *const in, if (header >= MAX_PACKET_TYPES) { - fprintf(stderr, "%s: invalid packet type %" PRIu8 "\n", + fprintf(stderr, "%s: invalid packet type %#" PRIx8 "\n", __func__, header); return -1; } diff --git a/src/sfx/CMakeLists.txt b/src/sfx/CMakeLists.txt index f503408..f36931d 100644 --- a/src/sfx/CMakeLists.txt +++ b/src/sfx/CMakeLists.txt @@ -17,21 +17,3 @@ add_library(sfx ${src}) target_include_directories(sfx PUBLIC ${inc}) target_include_directories(sfx PRIVATE ${privinc}) target_link_libraries(sfx PUBLIC ${deps} PRIVATE ${privdeps}) - -if(PS1_BUILD) - set(modes VMODE_PAL VMODE_NTSC) - - if(VIDEO_MODE) - if(NOT "${VIDEO_MODE}" IN_LIST modes) - message(FATAL_ERROR "Invalid video mode ${VIDEO_MODE}. Available options:\n" - "${modes}\n" - "Run CMake again using one of the available video modes e.g.: cmake .. -DVIDEO_MODE=VMODE_PAL") - endif() - - target_compile_definitions(sfx PRIVATE VIDEO_MODE=${VIDEO_MODE}) - else() - message(FATAL_ERROR "Please define video mode. Available options:\n" - "${modes}\n" - "Run CMake again using one of the available video modes e.g.: cmake .. -DVIDEO_MODE=VMODE_PAL") - endif() -endif() diff --git a/src/transport/src/heap.c b/src/transport/src/heap.c index cf43426..bcf0d6f 100644 --- a/src/transport/src/heap.c +++ b/src/transport/src/heap.c @@ -74,12 +74,12 @@ int transport_pop(struct transport_handle *const h) if (!h->n_packets) return -1; - union transport_packet *const p = h->packets[h->n_packets - 1]; + union transport_packet *const p = h->packets[--h->n_packets]; - if (--h->n_packets) + if (h->n_packets) { if (!(h->packets = realloc(h->packets, - (h->n_packets - 1) * sizeof *h->packets))) + h->n_packets * sizeof *h->packets))) return -1; } else diff --git a/src/transport/src/transport.c b/src/transport/src/transport.c index fe2d54f..52093d4 100644 --- a/src/transport/src/transport.c +++ b/src/transport/src/transport.c @@ -34,7 +34,7 @@ int transport_disconnect(struct transport_handle *const h) int transport_send(struct transport_handle *const h, const void *const buf, size_t n) { - const char *b = buf; + const uint8_t *b = buf; while (n) { @@ -98,7 +98,7 @@ static int read_header(const struct transport_cfg *const cfg, if (header >= MAX_TRANSPORT_PACKET_TYPES) { - fprintf(stderr, "%s: invalid header %" PRIu8 "\n", + fprintf(stderr, "%s: invalid header %#" PRIx8 "\n", __func__, header); return -1; } @@ -239,7 +239,8 @@ static int read_checksum(const struct transport_cfg *const cfg, if (checksum != expected) { - fprintf(stderr, "%s: invalid checksum %#" PRIx8 ", expected %#" PRIx8, + fprintf(stderr, "%s: invalid checksum %#" PRIx8 + ", expected %#" PRIx8 "\n", __func__, checksum, expected); return -1; } @@ -319,25 +320,15 @@ static void send_event(const struct transport_cfg *const cfg, } static int remove_packet(struct transport_handle *const h, - union transport_packet *const p) + union transport_packet **const pp) { - for (size_t i = 0; i < h->n_packets; i++) - { - union transport_packet **pp = &h->packets[i]; + size_t i = pp - h->packets; + const size_t n = i + 1; - if (*pp == p) - { - if (i + 1 < h->n_packets) - for (union transport_packet **pr = &h->packets[i + 1]; - pr - h->packets < h->n_packets; - pp++, pr++) - *pp = *pr; + if (n < h->n_packets) + memmove(pp, pp + 1, h->n_packets - n); - return transport_pop(h); - } - } - - return -1; + return transport_pop(h); } static void get_event(const struct transport_cfg *const cfg, @@ -367,13 +358,14 @@ static int process_ack(struct transport_handle *const h, { for (size_t i = 0; i < h->n_packets; i++) { - union transport_packet *const p = h->packets[i]; + union transport_packet **const pp = &h->packets[i]; + const union transport_packet *const p = *pp; if (p->common.ttl && a->checksum == calc_checksum(p)) { get_event(&h->cfg, p, &h->input.ev); - if (remove_packet(h, p)) + if (remove_packet(h, pp)) return -1; break; diff --git a/src/transport/test/test.c b/src/transport/test/test.c index 2bb8e7f..971f849 100644 --- a/src/transport/test/test.c +++ b/src/transport/test/test.c @@ -103,29 +103,25 @@ static void server_received(const struct transport_event *const ev, static int loop(struct server *const s, struct client *const c) { - if (transport_update(&s->h)) - return -1; - - if (!freopen("client", "w+b", s->io.in)) + if (transport_update(&s->h) + || !freopen("client", "w+b", s->io.in)) return -1; rewind(s->io.out); - if (transport_update(&c->h)) - return -1; - - if (!freopen("server", "w+b", c->io.in)) + if (transport_update(&c->h) + || !freopen("server", "w+b", c->io.in)) return -1; rewind(c->io.out); - return 0; } int main(void) { int ret = EXIT_FAILURE; - FILE *const cf = fopen("client", "w+b"), *sf = fopen("server", "w+b"); + FILE *const cf = fopen("client", "w+b"), + *const sf = fopen("server", "w+b"); if (!cf) { |
