From 4da7a3e44d2bbd7b21ae05c7b6604748e7227227 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Thu, 8 Dec 2022 16:31:24 +0100 Subject: [PATCH] wip2 --- README.md | 2 +- cmake/ps1.cmake | 21 ++++++++++++++- doc/BUILD-win9x.md | 14 +--------- src/CMakeLists.txt | 4 ++- src/gui/CMakeLists.txt | 1 + src/gui/inc/gui/combo_box.h | 29 +++++++++++++++++++++ src/gui/src/button.c | 6 ++--- src/gui/src/button_sprite.c | 31 ++++++++++++++++++++++ src/gui/src/combo_box.c | 43 +++++++++++++++++++++++++++++++ src/input/privinc/input_private.h | 19 ++++++++++++++ src/input/src/vkeyboard.c | 13 ++++++++++ src/net/ps1/src/net.c | 5 ++-- src/net/win9x/src/serial.c | 17 ++++++++++++ src/packet/src/packet.c | 2 +- src/sfx/CMakeLists.txt | 18 ------------- src/transport/src/heap.c | 6 ++--- src/transport/src/transport.c | 34 ++++++++++-------------- src/transport/test/test.c | 16 +++++------- 18 files changed, 207 insertions(+), 74 deletions(-) create mode 100644 src/gui/inc/gui/combo_box.h create mode 100644 src/gui/src/button_sprite.c create mode 100644 src/gui/src/combo_box.c create mode 100644 src/input/privinc/input_private.h create mode 100644 src/input/src/vkeyboard.c diff --git a/README.md b/README.md index 9564516..4df253e 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ process: mkdir build cd build cmake .. -make -j$(nproc --all) +cmake --build . -j$(nproc --all) ``` #### Dependencies diff --git a/cmake/ps1.cmake b/cmake/ps1.cmake index 33521f5..bbc1c4c 100644 --- a/cmake/ps1.cmake +++ b/cmake/ps1.cmake @@ -6,7 +6,26 @@ add_custom_target(exe ALL elf2exe ${PROJECT_NAME} DEPENDS ${PROJECT_NAME}) add_custom_target(iso ALL mkisofs -o ${PROJECT_NAME}.iso -V ${PROJECT_NAME} -sysid PLAYSTATION ${cdroot} DEPENDS exe) -set(license $ENV{PSXSDK_PATH}/share/licenses/infoeur.dat) + +set(license_prefix $ENV{PSXSDK_PATH}/share/licenses) + +if(VIDEO_MODE STREQUAL "VMODE_PAL") + set(region eur) +elseif(VIDEO_MODE STREQUAL "VMODE_NTSC") + set(ntsc_regions usa jap) + + if(NOT NTSC_REGION IN_LIST ntsc_regions) + message(FATAL_ERROR "Please define valid NTSC_REGION. Available options:\n" + "${ntsc_regions}\n" + "Run CMake again using one of the available options above e.g.:\n" + "cmake .. [options] -DNTSC_REGION=US") + endif() + + set(region ${NTSC_REGION}) +endif() + +set(license $ENV{PSXSDK_PATH}/share/licenses/info${region}.dat) + add_custom_target(bin_cue ALL mkpsxiso ${PROJECT_NAME}.iso ${PROJECT_NAME}.bin ${license} -s DEPENDS iso) diff --git a/doc/BUILD-win9x.md b/doc/BUILD-win9x.md index 3066b46..829003a 100644 --- a/doc/BUILD-win9x.md +++ b/doc/BUILD-win9x.md @@ -16,9 +16,8 @@ Since it is desirable to avoid messing with system-level libraries, when building for Win9x, `rts` will look for dependencies by inspecting the following environment variables: -- `SDL_PATH` +- `SDLDIR` - `SDL_TTF_PATH` -- `FREETYPE_PATH` - `SDL_MIXER_PATH` Also, the directory containing the GNU toolchain binaries (which @@ -73,17 +72,6 @@ cd mingwrt-3.15.2-mingw32/ && cp -r include/* ~/i386-mingw32/include/ [mingw-w32api-3.13](https://sourceforge.net/projects/mingw/files/OldFiles/w32api-3.13/w32api-3.13-mingw32-src.tar.gz) -## freetype (not required) -Only `freetype-2.4.8` is known to work so far. - -### Known issues -- Apparently, out of source builds are not possible. - -```sh -cd freetype-2.4.8-src/ && ./configure --prefix=$HOME/freetype-2.4.8 \ - --host=i386-mingw32 --enable-shared=no CC=i386-mingw32-gcc -``` - ## SDL `sdl-1.2.15` is the latest version supported version for the Win9x family of operating systems. In order to keep things easy, the script below 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 +#include +#include +#include + +#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 +#include +#include +#include +#include +#include + +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 +#include +#include +#include +#include + +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 +#include + +#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 +#include +#include + +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 #include #include +#include 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 #include #include +#include #include #include #include @@ -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) {