This commit is contained in:
Xavier Del Campo Romero 2022-12-08 16:31:24 +01:00
parent de3532bd6b
commit 4da7a3e44d
18 changed files with 207 additions and 74 deletions

View File

@ -49,7 +49,7 @@ process:
mkdir build mkdir build
cd build cd build
cmake .. cmake ..
make -j$(nproc --all) cmake --build . -j$(nproc --all)
``` ```
#### Dependencies #### Dependencies

View File

@ -6,7 +6,26 @@ add_custom_target(exe ALL elf2exe ${PROJECT_NAME}
DEPENDS ${PROJECT_NAME}) DEPENDS ${PROJECT_NAME})
add_custom_target(iso ALL mkisofs -o ${PROJECT_NAME}.iso -V ${PROJECT_NAME} add_custom_target(iso ALL mkisofs -o ${PROJECT_NAME}.iso -V ${PROJECT_NAME}
-sysid PLAYSTATION ${cdroot} DEPENDS exe) -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 add_custom_target(bin_cue ALL mkpsxiso ${PROJECT_NAME}.iso ${PROJECT_NAME}.bin
${license} -s DEPENDS iso) ${license} -s DEPENDS iso)

View File

@ -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 when building for Win9x, `rts` will look for dependencies by inspecting
the following environment variables: the following environment variables:
- `SDL_PATH` - `SDLDIR`
- `SDL_TTF_PATH` - `SDL_TTF_PATH`
- `FREETYPE_PATH`
- `SDL_MIXER_PATH` - `SDL_MIXER_PATH`
Also, the directory containing the GNU toolchain binaries (which 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) [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
`sdl-1.2.15` is the latest version supported version for the Win9x family `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 of operating systems. In order to keep things easy, the script below

View File

@ -1,5 +1,5 @@
# Avoid C11 since it is not supported by the i386-mingw32 toolchain. # 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 set(components
building building
@ -41,6 +41,8 @@ target_link_libraries(${PROJECT_NAME} PRIVATE system menu)
foreach(c ${components}) foreach(c ${components})
add_subdirectory("${c}") add_subdirectory("${c}")
target_compile_options(${c} PUBLIC ${cflags}) 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() endforeach()
foreach(i ${interfaces}) foreach(i ${interfaces})

View File

@ -1,6 +1,7 @@
add_library(gui add_library(gui
"src/bar.c" "src/bar.c"
"src/button.c" "src/button.c"
"src/button_sprite.c"
"src/button_type1.c" "src/button_type1.c"
"src/checkbox.c" "src/checkbox.c"
"src/container.c" "src/container.c"

View File

@ -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 */

View File

@ -14,7 +14,7 @@ static int render(const struct gui_common *const g)
static int (*const f[])(const struct gui_button *) = static int (*const f[])(const struct gui_button *) =
{ {
[GUI_BUTTON_TYPE_1] = gui_button_render_type1, [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; 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 *) = static void (*const f[])(const struct gui_button *, short *, short *) =
{ {
[GUI_BUTTON_TYPE_1] = gui_button_get_dim_type1, [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; 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 *) = static void (*const f[])(struct gui_button *) =
{ {
[GUI_BUTTON_TYPE_1] = gui_button_init_type1, [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); f[b->type](b);

View File

@ -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)
{
}

43
src/gui/src/combo_box.c Normal file
View File

@ -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);
}

View File

@ -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 */

13
src/input/src/vkeyboard.c Normal file
View File

@ -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;
}

View File

@ -7,6 +7,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h>
static struct net_host static struct net_host
{ {
@ -82,7 +83,7 @@ static int on_write(const void *const buf, size_t n, void *const arg)
EnterCriticalSection(); 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; struct net_host_fifo *const f = &h->out;
size_t new = f->pending + 1; 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(); EnterCriticalSection();
for (char *b = buf; rem; rem--, b++) for (uint8_t *b = buf; rem; rem--, b++)
{ {
if (f->read == f->pending) if (f->read == f->pending)
goto end; goto end;

View File

@ -1,6 +1,7 @@
#include <net.h> #include <net.h>
#include <net_private.h> #include <net_private.h>
#include <windows.h> #include <windows.h>
#include <ctype.h>
#include <errno.h> #include <errno.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.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()); __func__, GetLastError());
goto failure; 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); return get_result(h, r);

View File

@ -79,7 +79,7 @@ static int read_header(struct packet_input *const in,
if (header >= MAX_PACKET_TYPES) if (header >= MAX_PACKET_TYPES)
{ {
fprintf(stderr, "%s: invalid packet type %" PRIu8 "\n", fprintf(stderr, "%s: invalid packet type %#" PRIx8 "\n",
__func__, header); __func__, header);
return -1; return -1;
} }

View File

@ -17,21 +17,3 @@ add_library(sfx ${src})
target_include_directories(sfx PUBLIC ${inc}) target_include_directories(sfx PUBLIC ${inc})
target_include_directories(sfx PRIVATE ${privinc}) target_include_directories(sfx PRIVATE ${privinc})
target_link_libraries(sfx PUBLIC ${deps} PRIVATE ${privdeps}) 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()

View File

@ -74,12 +74,12 @@ int transport_pop(struct transport_handle *const h)
if (!h->n_packets) if (!h->n_packets)
return -1; 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, if (!(h->packets = realloc(h->packets,
(h->n_packets - 1) * sizeof *h->packets))) h->n_packets * sizeof *h->packets)))
return -1; return -1;
} }
else else

View File

@ -34,7 +34,7 @@ int transport_disconnect(struct transport_handle *const h)
int transport_send(struct transport_handle *const h, int transport_send(struct transport_handle *const h,
const void *const buf, size_t n) const void *const buf, size_t n)
{ {
const char *b = buf; const uint8_t *b = buf;
while (n) while (n)
{ {
@ -98,7 +98,7 @@ static int read_header(const struct transport_cfg *const cfg,
if (header >= MAX_TRANSPORT_PACKET_TYPES) if (header >= MAX_TRANSPORT_PACKET_TYPES)
{ {
fprintf(stderr, "%s: invalid header %" PRIu8 "\n", fprintf(stderr, "%s: invalid header %#" PRIx8 "\n",
__func__, header); __func__, header);
return -1; return -1;
} }
@ -239,7 +239,8 @@ static int read_checksum(const struct transport_cfg *const cfg,
if (checksum != expected) if (checksum != expected)
{ {
fprintf(stderr, "%s: invalid checksum %#" PRIx8 ", expected %#" PRIx8, fprintf(stderr, "%s: invalid checksum %#" PRIx8
", expected %#" PRIx8 "\n",
__func__, checksum, expected); __func__, checksum, expected);
return -1; 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, 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++) size_t i = pp - h->packets;
{ const size_t n = i + 1;
union transport_packet **pp = &h->packets[i];
if (*pp == p) if (n < h->n_packets)
{ memmove(pp, pp + 1, h->n_packets - n);
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;
return transport_pop(h); return transport_pop(h);
}
}
return -1;
} }
static void get_event(const struct transport_cfg *const cfg, 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++) 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)) if (p->common.ttl && a->checksum == calc_checksum(p))
{ {
get_event(&h->cfg, p, &h->input.ev); get_event(&h->cfg, p, &h->input.ev);
if (remove_packet(h, p)) if (remove_packet(h, pp))
return -1; return -1;
break; break;

View File

@ -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) static int loop(struct server *const s, struct client *const c)
{ {
if (transport_update(&s->h)) if (transport_update(&s->h)
return -1; || !freopen("client", "w+b", s->io.in))
if (!freopen("client", "w+b", s->io.in))
return -1; return -1;
rewind(s->io.out); rewind(s->io.out);
if (transport_update(&c->h)) if (transport_update(&c->h)
return -1; || !freopen("server", "w+b", c->io.in))
if (!freopen("server", "w+b", c->io.in))
return -1; return -1;
rewind(c->io.out); rewind(c->io.out);
return 0; return 0;
} }
int main(void) int main(void)
{ {
int ret = EXIT_FAILURE; 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) if (!cf)
{ {