00cc9309cb
de6e324bdseparate emu thread10d3daf86Roms List improvements95d202f37Let's make the rom list process on a separate thread so the emulator doesnt take ages to load.fc306967fWow the ROM Header was just completely busted. Game list view works nowbad1691eefuck this shit2b59e5f46game list in progressd26417b83remappable inputs in progressac4af8106inpute72abc240update readme430139dc9Qt6 frontend3080d4d45Fix this small bug too08cd13b85Cop0 unused functions do not actually pose a threat (as per manual). They don't do anything, so shall we.61bb4fb44make idle loop detection a little more specific with where the load goesb037de4c3SAZDFsdff12e81e73eneed to figure out why n64-systemtest loops indefinitely at some address that appears to be valid (i think it's me not invalidating the cache properly)204f0e13bidle skipping seems to work!cb8bb634asdkfjlasdf58e5c89c1Fix compilation issue on my machine (no idea)24fb2898eattempting more serious idle skipping214719577Place rsp.Step inside cached interpreter. Gains about 3 more fpsbb97dcc23mmmmm920b77d38wjkhasdfjhkasdf430ccdab4it's a start...4f42a673aCached interpreter plays Mario 64. Start looking into RSP as wellc9a030787idle skipping works!5fbda03cenew idea366637abaIdle skipping... maybe?609fa2fb0Cache instructions implemented but broken lmao. Commented out for nowe140a6d12- Stop using inheritance for CPU, instead use composition. - Introduce KAIZEN_JIT_ENABLED optional define instead of relying on __aarch64__ and the like. - More cache work68e613057prep cache impl811b4d809fix clang formatfda755f7didkd5024ebbfsmall MI refactor in preparation of (eventually) implementing the RDRAM interface properly694b45341Merge commit '206dcdedf195fb320913584180edb12c7731e396' as 'external/SDL'206dcdedfSquashed 'external/SDL/' content from commit 4d17b99d0a4d16e1cb4need to update sdl848b19920Fix compilation errordb61b5299Merge commit 'e94a94559f28e49678fbcf72199a5258137b0fe9' as 'external/imgui'e94a94559Squashed 'external/imgui/' content from commit 02e9b8cac52edb3757need to update imguic1a705e86Emulate weird JALR behaviour4b4c32f4bFix exception for "unusable COP1" in 4 instructions i missed accidentally (again)df5828142Bug putting 0s in the log everywheref8b580048Make isviewer a sink to file8241e9735Fix exception for "unusable COP1" in 4 instructions i missed accidentallyb29715f20small changesd9a620bc1make use of my new small utility library0d1aa938eAdd 'external/ircolib/' from commit 'ce3cd726c8df8388d554abf8bb55d55020eb4450'e64eb40b3Fuck git git-subtree-dir: external/ircolib git-subtree-split:de6e324bde
343 lines
11 KiB
C
343 lines
11 KiB
C
/*
|
|
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
warranty. In no event will the authors be held liable for any damages
|
|
arising from the use of this software.
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
including commercial applications, and to alter it and redistribute it
|
|
freely.
|
|
*/
|
|
|
|
#include <SDL3/SDL.h>
|
|
#include <SDL3/SDL_test.h>
|
|
#include <wayland-client.h>
|
|
#include <xdg-shell-client-protocol.h>
|
|
|
|
#include "icon.h"
|
|
|
|
#define WINDOW_WIDTH 640
|
|
#define WINDOW_HEIGHT 480
|
|
#define NUM_SPRITES 100
|
|
#define MAX_SPEED 1
|
|
|
|
static SDL_Window *window;
|
|
static SDL_Renderer *renderer;
|
|
static SDL_Texture *sprite;
|
|
static SDL_FRect positions[NUM_SPRITES];
|
|
static SDL_FRect velocities[NUM_SPRITES];
|
|
static int sprite_w, sprite_h;
|
|
static int done;
|
|
|
|
static SDL_Texture *CreateTexture(SDL_Renderer *r, unsigned char *data, unsigned int len, int *w, int *h)
|
|
{
|
|
SDL_Texture *texture = NULL;
|
|
SDL_Surface *surface;
|
|
SDL_IOStream *src = SDL_IOFromConstMem(data, len);
|
|
if (src) {
|
|
surface = SDL_LoadPNG_IO(src, true);
|
|
if (surface) {
|
|
/* Treat white as transparent */
|
|
SDL_SetSurfaceColorKey(surface, true, SDL_MapSurfaceRGB(surface, 255, 255, 255));
|
|
|
|
texture = SDL_CreateTextureFromSurface(r, surface);
|
|
*w = surface->w;
|
|
*h = surface->h;
|
|
SDL_DestroySurface(surface);
|
|
}
|
|
}
|
|
return texture;
|
|
}
|
|
|
|
static void MoveSprites(void)
|
|
{
|
|
int i;
|
|
int window_w;
|
|
int window_h;
|
|
SDL_FRect *position, *velocity;
|
|
|
|
/* Get the window size */
|
|
SDL_GetWindowSizeInPixels(window, &window_w, &window_h);
|
|
|
|
/* Draw a gray background */
|
|
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
|
SDL_RenderClear(renderer);
|
|
|
|
/* Move the sprite, bounce at the wall, and draw */
|
|
for (i = 0; i < NUM_SPRITES; ++i) {
|
|
position = &positions[i];
|
|
velocity = &velocities[i];
|
|
position->x += velocity->x;
|
|
if ((position->x < 0) || (position->x >= (window_w - sprite_w))) {
|
|
velocity->x = -velocity->x;
|
|
position->x += velocity->x;
|
|
}
|
|
position->y += velocity->y;
|
|
if ((position->y < 0) || (position->y >= (window_h - sprite_h))) {
|
|
velocity->y = -velocity->y;
|
|
position->y += velocity->y;
|
|
}
|
|
|
|
/* Blit the sprite onto the screen */
|
|
SDL_RenderTexture(renderer, sprite, NULL, position);
|
|
}
|
|
|
|
/* Update the screen! */
|
|
SDL_RenderPresent(renderer);
|
|
}
|
|
|
|
static int InitSprites(void)
|
|
{
|
|
/* Create the sprite texture and initialize the sprite positions */
|
|
sprite = CreateTexture(renderer, icon_png, icon_png_len, &sprite_w, &sprite_h);
|
|
|
|
if (!sprite) {
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to create sprite texture");
|
|
return -1;
|
|
}
|
|
|
|
for (int i = 0; i < NUM_SPRITES; ++i) {
|
|
positions[i].x = (float)SDL_rand(WINDOW_WIDTH - sprite_w);
|
|
positions[i].y = (float)SDL_rand(WINDOW_HEIGHT - sprite_h);
|
|
positions[i].w = (float)sprite_w;
|
|
positions[i].h = (float)sprite_h;
|
|
velocities[i].x = 0.0f;
|
|
velocities[i].y = 0.0f;
|
|
while (velocities[i].x == 0.f && velocities[i].y == 0.f) {
|
|
velocities[i].x = (float)(SDL_rand(MAX_SPEED * 2 + 1) - MAX_SPEED);
|
|
velocities[i].y = (float)(SDL_rand(MAX_SPEED * 2 + 1) - MAX_SPEED);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* Encapsulated in a struct to silence shadow variable warnings */
|
|
static struct
|
|
{
|
|
/* These are owned by SDL and must not be destroyed! */
|
|
struct wl_display *wl_display;
|
|
struct wl_surface *wl_surface;
|
|
|
|
/* These are owned by the application and need to be cleaned up on exit. */
|
|
struct wl_registry *wl_registry;
|
|
struct xdg_wm_base *xdg_wm_base;
|
|
struct xdg_surface *xdg_surface;
|
|
struct xdg_toplevel *xdg_toplevel;
|
|
} test_wl_state;
|
|
|
|
static void xdg_surface_configure(void *data, struct xdg_surface *xdg_surface, uint32_t serial)
|
|
{
|
|
xdg_surface_ack_configure(test_wl_state.xdg_surface, serial);
|
|
}
|
|
|
|
static const struct xdg_surface_listener xdg_surface_listener = {
|
|
.configure = xdg_surface_configure,
|
|
};
|
|
|
|
static void xdg_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel, int32_t width, int32_t height, struct wl_array *states)
|
|
{
|
|
/* NOP */
|
|
}
|
|
|
|
static void xdg_toplevel_close(void *data, struct xdg_toplevel *xdg_toplevel)
|
|
{
|
|
done = 1;
|
|
}
|
|
|
|
static void xdg_toplevel_configure_bounds(void *data, struct xdg_toplevel *xdg_toplevel, int32_t width, int32_t height)
|
|
{
|
|
/* NOP */
|
|
}
|
|
|
|
static void xdg_toplevel_wm_capabilities(void *data, struct xdg_toplevel *xdg_toplevel, struct wl_array *capabilities)
|
|
{
|
|
/* NOP */
|
|
}
|
|
|
|
static const struct xdg_toplevel_listener xdg_toplevel_listener = {
|
|
.configure = xdg_toplevel_configure,
|
|
.close = xdg_toplevel_close,
|
|
.configure_bounds = xdg_toplevel_configure_bounds,
|
|
.wm_capabilities = xdg_toplevel_wm_capabilities
|
|
};
|
|
|
|
static void xdg_wm_base_ping(void *data, struct xdg_wm_base *xdg_wm_base, uint32_t serial)
|
|
{
|
|
xdg_wm_base_pong(test_wl_state.xdg_wm_base, serial);
|
|
}
|
|
|
|
static const struct xdg_wm_base_listener xdg_wm_base_listener = {
|
|
.ping = xdg_wm_base_ping,
|
|
};
|
|
|
|
static void registry_global(void *data, struct wl_registry *wl_registry, uint32_t name, const char *interface, uint32_t version)
|
|
{
|
|
if (SDL_strcmp(interface, xdg_wm_base_interface.name) == 0) {
|
|
test_wl_state.xdg_wm_base = wl_registry_bind(test_wl_state.wl_registry, name, &xdg_wm_base_interface, 1);
|
|
xdg_wm_base_add_listener(test_wl_state.xdg_wm_base, &xdg_wm_base_listener, NULL);
|
|
}
|
|
}
|
|
|
|
static void registry_global_remove(void *data, struct wl_registry *wl_registry, uint32_t name)
|
|
{
|
|
/* NOP */
|
|
}
|
|
|
|
static const struct wl_registry_listener wl_registry_listener = {
|
|
.global = registry_global,
|
|
.global_remove = registry_global_remove,
|
|
};
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
int ret = -1;
|
|
SDL_PropertiesID props;
|
|
SDLTest_CommonState *state;
|
|
|
|
state = SDLTest_CommonCreateState(argv, 0);
|
|
if (!state) {
|
|
return 1;
|
|
}
|
|
|
|
if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
|
|
goto exit;
|
|
}
|
|
|
|
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS)) {
|
|
goto exit;
|
|
}
|
|
|
|
if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland") != 0) {
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Video driver must be 'wayland', not '%s'", SDL_GetCurrentVideoDriver());
|
|
goto exit;
|
|
}
|
|
|
|
/* Create a window with the custom surface role property set. */
|
|
props = SDL_CreateProperties();
|
|
SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_WAYLAND_SURFACE_ROLE_CUSTOM_BOOLEAN, true); /* Roleless surface */
|
|
SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_OPENGL_BOOLEAN, true); /* OpenGL enabled */
|
|
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, WINDOW_WIDTH); /* Default width */
|
|
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, WINDOW_HEIGHT); /* Default height */
|
|
SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_HIGH_PIXEL_DENSITY_BOOLEAN, true); /* Handle DPI scaling internally */
|
|
SDL_SetStringProperty(props, SDL_PROP_WINDOW_CREATE_TITLE_STRING, "Wayland custom surface role test"); /* Default title */
|
|
|
|
window = SDL_CreateWindowWithProperties(props);
|
|
SDL_DestroyProperties(props);
|
|
if (!window) {
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation failed");
|
|
goto exit;
|
|
}
|
|
|
|
/* Create the renderer */
|
|
renderer = SDL_CreateRenderer(window, NULL);
|
|
if (!renderer) {
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Renderer creation failed");
|
|
goto exit;
|
|
}
|
|
|
|
/* Get the display object and use it to create a registry object, which will enumerate the xdg_wm_base protocol. */
|
|
test_wl_state.wl_display = SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_WAYLAND_DISPLAY_POINTER, NULL);
|
|
test_wl_state.wl_registry = wl_display_get_registry(test_wl_state.wl_display);
|
|
wl_registry_add_listener(test_wl_state.wl_registry, &wl_registry_listener, NULL);
|
|
|
|
/* Roundtrip to enumerate registry objects. */
|
|
wl_display_roundtrip(test_wl_state.wl_display);
|
|
|
|
if (!test_wl_state.xdg_wm_base) {
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "'xdg_wm_base' protocol not found!");
|
|
goto exit;
|
|
}
|
|
|
|
/* Get the wl_surface object from the SDL_Window, and create a toplevel window with it. */
|
|
test_wl_state.wl_surface = SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_WAYLAND_SURFACE_POINTER, NULL);
|
|
|
|
/* Create the xdg_surface from the wl_surface. */
|
|
test_wl_state.xdg_surface = xdg_wm_base_get_xdg_surface(test_wl_state.xdg_wm_base, test_wl_state.wl_surface);
|
|
xdg_surface_add_listener(test_wl_state.xdg_surface, &xdg_surface_listener, NULL);
|
|
|
|
/* Create the xdg_toplevel from the xdg_surface. */
|
|
test_wl_state.xdg_toplevel = xdg_surface_get_toplevel(test_wl_state.xdg_surface);
|
|
xdg_toplevel_add_listener(test_wl_state.xdg_toplevel, &xdg_toplevel_listener, NULL);
|
|
xdg_toplevel_set_title(test_wl_state.xdg_toplevel, SDL_GetWindowTitle(window));
|
|
|
|
/* Initialize the sprites. */
|
|
if (InitSprites() < 0) {
|
|
goto exit;
|
|
}
|
|
|
|
while (!done) {
|
|
SDL_Event event;
|
|
while (SDL_PollEvent(&event)) {
|
|
if (event.type == SDL_EVENT_KEY_DOWN) {
|
|
switch (event.key.key) {
|
|
case SDLK_ESCAPE:
|
|
done = 1;
|
|
break;
|
|
case SDLK_EQUALS:
|
|
/* Ctrl+ enlarges the window */
|
|
if (event.key.mod & SDL_KMOD_CTRL) {
|
|
int w, h;
|
|
SDL_GetWindowSize(window, &w, &h);
|
|
SDL_SetWindowSize(window, w * 2, h * 2);
|
|
}
|
|
break;
|
|
case SDLK_MINUS:
|
|
/* Ctrl- shrinks the window */
|
|
if (event.key.mod & SDL_KMOD_CTRL) {
|
|
int w, h;
|
|
SDL_GetWindowSize(window, &w, &h);
|
|
SDL_SetWindowSize(window, w / 2, h / 2);
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
/* Draw the sprites */
|
|
MoveSprites();
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
exit:
|
|
/* The display and surface handles obtained from SDL are owned by SDL and must *NOT* be destroyed here! */
|
|
if (test_wl_state.xdg_toplevel) {
|
|
xdg_toplevel_destroy(test_wl_state.xdg_toplevel);
|
|
test_wl_state.xdg_toplevel = NULL;
|
|
}
|
|
if (test_wl_state.xdg_surface) {
|
|
xdg_surface_destroy(test_wl_state.xdg_surface);
|
|
test_wl_state.xdg_surface = NULL;
|
|
}
|
|
if (test_wl_state.xdg_wm_base) {
|
|
xdg_wm_base_destroy(test_wl_state.xdg_wm_base);
|
|
test_wl_state.xdg_wm_base = NULL;
|
|
}
|
|
if (test_wl_state.wl_registry) {
|
|
wl_registry_destroy(test_wl_state.wl_registry);
|
|
test_wl_state.wl_registry = NULL;
|
|
}
|
|
|
|
/* Destroy the SDL resources */
|
|
if (sprite) {
|
|
SDL_DestroyTexture(sprite);
|
|
sprite = NULL;
|
|
}
|
|
if (renderer) {
|
|
SDL_DestroyRenderer(renderer);
|
|
renderer = NULL;
|
|
}
|
|
if (window) {
|
|
SDL_DestroyWindow(window);
|
|
window = NULL;
|
|
}
|
|
|
|
SDL_Quit();
|
|
SDLTest_CommonDestroyState(state);
|
|
return ret;
|
|
}
|