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
552 lines
16 KiB
C
552 lines
16 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_test_common.h>
|
|
#include <SDL3/SDL_main.h>
|
|
|
|
/* Stolen from the mailing list */
|
|
/* Creates a new mouse cursor from an XPM */
|
|
|
|
/* XPM */
|
|
static const char *arrow[] = {
|
|
/* width height num_colors chars_per_pixel */
|
|
" 32 32 3 1",
|
|
/* colors */
|
|
"X c #000000",
|
|
". c #ffffff",
|
|
" c None",
|
|
/* pixels */
|
|
"X ",
|
|
"XX ",
|
|
"X.X ",
|
|
"X..X ",
|
|
"X...X ",
|
|
"X....X ",
|
|
"X.....X ",
|
|
"X......X ",
|
|
"X.......X ",
|
|
"X........X ",
|
|
"X.....XXXXX ",
|
|
"X..X..X ",
|
|
"X.X X..X ",
|
|
"XX X..X ",
|
|
"X X..X ",
|
|
" X..X ",
|
|
" X..X ",
|
|
" X..X ",
|
|
" XX ",
|
|
" ",
|
|
" ",
|
|
" ",
|
|
" ",
|
|
" ",
|
|
" ",
|
|
" ",
|
|
" ",
|
|
" ",
|
|
" ",
|
|
" ",
|
|
" ",
|
|
" ",
|
|
"0,0"
|
|
};
|
|
|
|
static const char *cross[] = {
|
|
/* width height num_colors chars_per_pixel */
|
|
" 32 32 3 1",
|
|
/* colors */
|
|
"o c #ffffff",
|
|
". c #000000",
|
|
" c None",
|
|
/* pixels */
|
|
" ",
|
|
" ",
|
|
" ",
|
|
" ",
|
|
" oo ",
|
|
" oo ",
|
|
" oo ",
|
|
" oo ",
|
|
" oo ",
|
|
" oo ",
|
|
" oo ",
|
|
" oo ",
|
|
" oo ",
|
|
" oo ",
|
|
" oo ",
|
|
" oooooooooooooooooooooooo ",
|
|
" oooooooooooooooooooooooo ",
|
|
" oo ",
|
|
" oo ",
|
|
" oo ",
|
|
" oo ",
|
|
" oo ",
|
|
" oo ",
|
|
" oo ",
|
|
" oo ",
|
|
" oo ",
|
|
" oo ",
|
|
" oo ",
|
|
" ",
|
|
" ",
|
|
" ",
|
|
" ",
|
|
"0,0"
|
|
};
|
|
|
|
static SDLTest_CommonState *state;
|
|
static int done;
|
|
|
|
#define PROP_ARROW_CURSOR_TEXTURE "arrow_cursor_texture"
|
|
#define PROP_CROSS_CURSOR_TEXTURE "cross_cursor_texture"
|
|
#define MAX_MICE 3
|
|
#define MAX_KEYBOARDS 3
|
|
#define CURSOR_SIZE 48.0f
|
|
#define MAX_TRAIL 500
|
|
#define TRAIL_SIZE 8.0f
|
|
|
|
static SDL_Color colors[] = {
|
|
{ 0, 255, 255, 255 }, /* mouse 1, cyan */
|
|
{ 255, 0, 255, 255 }, /* mouse 2, magenta */
|
|
{ 255, 255, 0, 255 }, /* mouse 3, yellow */
|
|
};
|
|
SDL_COMPILE_TIME_ASSERT(mouse_colors, SDL_arraysize(colors) == MAX_MICE);
|
|
SDL_COMPILE_TIME_ASSERT(keyboard_colors, SDL_arraysize(colors) == MAX_KEYBOARDS);
|
|
|
|
typedef struct
|
|
{
|
|
SDL_MouseID instance_id;
|
|
bool active;
|
|
Uint8 button_state;
|
|
SDL_FPoint position;
|
|
int trail_head;
|
|
int trail_length;
|
|
SDL_FPoint trail[MAX_TRAIL];
|
|
} MouseState;
|
|
|
|
static MouseState mice[MAX_MICE];
|
|
|
|
typedef struct
|
|
{
|
|
SDL_KeyboardID instance_id;
|
|
bool active;
|
|
Uint8 button_state;
|
|
SDL_FPoint position;
|
|
} KeyboardState;
|
|
|
|
static KeyboardState keyboards[MAX_KEYBOARDS];
|
|
|
|
static SDL_Texture *CreateTexture(const char *image[], SDL_Renderer *renderer)
|
|
{
|
|
SDL_Surface *surface;
|
|
SDL_Palette *palette;
|
|
SDL_Texture *texture;
|
|
int row;
|
|
|
|
surface = SDL_CreateSurface(32, 32, SDL_PIXELFORMAT_INDEX8);
|
|
for (row = 0; row < surface->h; ++row) {
|
|
SDL_memcpy((Uint8 *)surface->pixels + row * surface->pitch, image[4 + row], surface->w);
|
|
}
|
|
|
|
palette = SDL_CreateSurfacePalette(surface);
|
|
if (!palette) {
|
|
SDL_DestroySurface(surface);
|
|
return NULL;
|
|
}
|
|
palette->colors['.'].r = 0xFF;
|
|
palette->colors['.'].g = 0xFF;
|
|
palette->colors['.'].b = 0xFF;
|
|
palette->colors['o'].r = 0xFF;
|
|
palette->colors['o'].g = 0xFF;
|
|
palette->colors['o'].b = 0xFF;
|
|
palette->colors['X'].r = 0x00;
|
|
palette->colors['X'].g = 0x00;
|
|
palette->colors['X'].b = 0x00;
|
|
|
|
SDL_SetSurfaceColorKey(surface, true, ' ');
|
|
|
|
texture = SDL_CreateTextureFromSurface(renderer, surface);
|
|
SDL_DestroySurface(surface);
|
|
return texture;
|
|
}
|
|
|
|
static void HandleMouseAdded(SDL_MouseID instance_id)
|
|
{
|
|
SDL_Window *window = state->windows[0];
|
|
int i, w = 0, h = 0;
|
|
|
|
SDL_GetWindowSizeInPixels(window, &w, &h);
|
|
|
|
for (i = 0; i < SDL_arraysize(mice); ++i) {
|
|
MouseState *mouse_state = &mice[i];
|
|
if (!mouse_state->active) {
|
|
mouse_state->instance_id = instance_id;
|
|
mouse_state->active = true;
|
|
mouse_state->position.x = w * 0.5f;
|
|
mouse_state->position.y = h * 0.5f;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
static void HandleMouseRemoved(SDL_MouseID instance_id)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < SDL_arraysize(mice); ++i) {
|
|
MouseState *mouse_state = &mice[i];
|
|
if (instance_id == mouse_state->instance_id) {
|
|
SDL_zerop(mouse_state);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
static void ActivateMouse(SDL_MouseID instance_id)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < SDL_arraysize(mice); ++i) {
|
|
MouseState *mouse_state = &mice[i];
|
|
if (mouse_state->active && instance_id == mouse_state->instance_id) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
HandleMouseAdded(instance_id);
|
|
}
|
|
|
|
static void HandleMouseMotion(SDL_MouseMotionEvent *event)
|
|
{
|
|
SDL_Window *window = state->windows[0];
|
|
int i, w = 0, h = 0;
|
|
|
|
if (event->which == 0) {
|
|
/* The system pointer, not a distinct mouse device */
|
|
return;
|
|
}
|
|
|
|
ActivateMouse(event->which);
|
|
|
|
SDL_GetWindowSizeInPixels(window, &w, &h);
|
|
|
|
for (i = 0; i < SDL_arraysize(mice); ++i) {
|
|
MouseState *mouse_state = &mice[i];
|
|
if (!mouse_state->active) {
|
|
continue;
|
|
}
|
|
if (event->which == mouse_state->instance_id) {
|
|
float x = (mouse_state->position.x + event->xrel);
|
|
float y = (mouse_state->position.y + event->yrel);
|
|
|
|
x = SDL_clamp(x, 0.0f, (float)w);
|
|
y = SDL_clamp(y, 0.0f, (float)h);
|
|
|
|
mouse_state->position.x = x;
|
|
mouse_state->position.y = y;
|
|
|
|
if (mouse_state->button_state) {
|
|
/* Add a spot to the mouse trail */
|
|
SDL_FPoint *spot = &mouse_state->trail[mouse_state->trail_head];
|
|
spot->x = x - TRAIL_SIZE * 0.5f;
|
|
spot->y = y - TRAIL_SIZE * 0.5f;
|
|
if (mouse_state->trail_length < MAX_TRAIL) {
|
|
++mouse_state->trail_length;
|
|
}
|
|
mouse_state->trail_head = (mouse_state->trail_head + 1) % MAX_TRAIL;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static void HandleMouseButton(SDL_MouseButtonEvent *event)
|
|
{
|
|
int i;
|
|
|
|
if (event->which == 0) {
|
|
/* The system pointer, not a distinct mouse device */
|
|
return;
|
|
}
|
|
|
|
ActivateMouse(event->which);
|
|
|
|
for (i = 0; i < SDL_arraysize(mice); ++i) {
|
|
MouseState *mouse_state = &mice[i];
|
|
if (!mouse_state->active) {
|
|
continue;
|
|
}
|
|
if (event->which == mouse_state->instance_id) {
|
|
if (event->down) {
|
|
mouse_state->button_state |= SDL_BUTTON_MASK(event->button);
|
|
} else {
|
|
mouse_state->button_state &= ~SDL_BUTTON_MASK(event->button);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static void DrawMouseState(SDL_Window *window, SDL_Renderer *renderer, MouseState *mouse_state, SDL_Texture *cursor, SDL_Color *color)
|
|
{
|
|
SDL_FRect rect;
|
|
|
|
if (!mouse_state->active) {
|
|
return;
|
|
}
|
|
|
|
if (mouse_state->trail_length > 0) {
|
|
int i;
|
|
int spot = mouse_state->trail_head - mouse_state->trail_length;
|
|
if (spot < 0) {
|
|
spot += MAX_TRAIL;
|
|
}
|
|
|
|
rect.w = TRAIL_SIZE;
|
|
rect.h = TRAIL_SIZE;
|
|
SDL_SetRenderDrawColor(renderer, color->r, color->g, color->b, color->a);
|
|
for (i = 0; i < mouse_state->trail_length; ++i) {
|
|
rect.x = mouse_state->trail[spot].x;
|
|
rect.y = mouse_state->trail[spot].y;
|
|
SDL_RenderFillRect(renderer, &rect);
|
|
spot = (spot + 1) % MAX_TRAIL;
|
|
}
|
|
}
|
|
|
|
rect.x = mouse_state->position.x;
|
|
rect.y = mouse_state->position.y;
|
|
rect.w = CURSOR_SIZE;
|
|
rect.h = CURSOR_SIZE;
|
|
SDL_SetTextureColorMod(cursor, color->r, color->g, color->b);
|
|
SDL_RenderTexture(renderer, cursor, NULL, &rect);
|
|
}
|
|
|
|
static void HandleKeyboardAdded(SDL_KeyboardID instance_id)
|
|
{
|
|
SDL_Window *window = state->windows[0];
|
|
int i, w = 0, h = 0;
|
|
|
|
SDL_GetWindowSize(window, &w, &h);
|
|
|
|
for (i = 0; i < SDL_arraysize(keyboards); ++i) {
|
|
KeyboardState *keyboard_state = &keyboards[i];
|
|
if (!keyboard_state->active) {
|
|
keyboard_state->instance_id = instance_id;
|
|
keyboard_state->active = true;
|
|
keyboard_state->position.x = w * 0.5f;
|
|
keyboard_state->position.y = h * 0.5f;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
static void HandleKeyboardRemoved(SDL_KeyboardID instance_id)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < SDL_arraysize(keyboards); ++i) {
|
|
KeyboardState *keyboard_state = &keyboards[i];
|
|
if (instance_id == keyboard_state->instance_id) {
|
|
SDL_zerop(keyboard_state);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
static void ActivateKeyboard(SDL_KeyboardID instance_id)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < SDL_arraysize(keyboards); ++i) {
|
|
KeyboardState *keyboard_state = &keyboards[i];
|
|
if (keyboard_state->active && instance_id == keyboard_state->instance_id) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
HandleKeyboardAdded(instance_id);
|
|
}
|
|
|
|
static void HandleKeyboardKeyDown(SDL_KeyboardEvent *event)
|
|
{
|
|
SDL_Window *window = state->windows[0];
|
|
int i, w = 0, h = 0;
|
|
|
|
SDL_GetWindowSize(window, &w, &h);
|
|
|
|
ActivateKeyboard(event->which);
|
|
|
|
for (i = 0; i < SDL_arraysize(keyboards); ++i) {
|
|
KeyboardState *keyboard_state = &keyboards[i];
|
|
if (!keyboard_state->active) {
|
|
continue;
|
|
}
|
|
if (event->which == keyboard_state->instance_id) {
|
|
switch (event->key) {
|
|
case SDLK_LEFT:
|
|
keyboard_state->position.x -= CURSOR_SIZE;
|
|
if (keyboard_state->position.x < 0.0f) {
|
|
keyboard_state->position.x = 0.0f;
|
|
}
|
|
break;
|
|
case SDLK_RIGHT:
|
|
keyboard_state->position.x += CURSOR_SIZE;
|
|
if (keyboard_state->position.x > w) {
|
|
keyboard_state->position.x = (float)w;
|
|
}
|
|
break;
|
|
case SDLK_UP:
|
|
keyboard_state->position.y -= CURSOR_SIZE;
|
|
if (keyboard_state->position.y < 0.0f) {
|
|
keyboard_state->position.y = 0.0f;
|
|
}
|
|
break;
|
|
case SDLK_DOWN:
|
|
keyboard_state->position.y += CURSOR_SIZE;
|
|
if (keyboard_state->position.y > h) {
|
|
keyboard_state->position.y = (float)h;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static void DrawKeyboardState(SDL_Window *window, SDL_Renderer *renderer, KeyboardState *keyboard_state, SDL_Texture *cursor, SDL_Color *color)
|
|
{
|
|
SDL_FRect rect;
|
|
|
|
if (!keyboard_state->active) {
|
|
return;
|
|
}
|
|
|
|
rect.x = keyboard_state->position.x - CURSOR_SIZE / 2;
|
|
rect.y = keyboard_state->position.y - CURSOR_SIZE / 2;
|
|
rect.w = CURSOR_SIZE;
|
|
rect.h = CURSOR_SIZE;
|
|
SDL_SetTextureColorMod(cursor, color->r, color->g, color->b);
|
|
SDL_RenderTexture(renderer, cursor, NULL, &rect);
|
|
}
|
|
|
|
static void loop(void)
|
|
{
|
|
int i, j;
|
|
SDL_Event event;
|
|
|
|
/* Check for events */
|
|
while (SDL_PollEvent(&event)) {
|
|
SDLTest_CommonEvent(state, &event, &done);
|
|
|
|
switch (event.type) {
|
|
case SDL_EVENT_KEYBOARD_ADDED:
|
|
/* Wait for events before activating this keyboard */
|
|
break;
|
|
case SDL_EVENT_KEYBOARD_REMOVED:
|
|
HandleKeyboardRemoved(event.kdevice.which);
|
|
break;
|
|
case SDL_EVENT_KEY_DOWN:
|
|
HandleKeyboardKeyDown(&event.key);
|
|
break;
|
|
case SDL_EVENT_MOUSE_ADDED:
|
|
/* Wait for events before activating this mouse */
|
|
break;
|
|
case SDL_EVENT_MOUSE_REMOVED:
|
|
HandleMouseRemoved(event.mdevice.which);
|
|
break;
|
|
case SDL_EVENT_MOUSE_MOTION:
|
|
HandleMouseMotion(&event.motion);
|
|
break;
|
|
case SDL_EVENT_MOUSE_BUTTON_DOWN:
|
|
case SDL_EVENT_MOUSE_BUTTON_UP:
|
|
HandleMouseButton(&event.button);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
for (i = 0; i < state->num_windows; ++i) {
|
|
SDL_Window *window = state->windows[i];
|
|
SDL_Renderer *renderer = state->renderers[i];
|
|
SDL_Texture *arrow_cursor = (SDL_Texture *)SDL_GetPointerProperty(SDL_GetRendererProperties(renderer), PROP_ARROW_CURSOR_TEXTURE, NULL);
|
|
SDL_Texture *cross_cursor = (SDL_Texture *)SDL_GetPointerProperty(SDL_GetRendererProperties(renderer), PROP_CROSS_CURSOR_TEXTURE, NULL);
|
|
|
|
SDL_SetRenderDrawColor(renderer, 128, 128, 128, 255);
|
|
SDL_RenderClear(renderer);
|
|
|
|
for (j = 0; j < SDL_arraysize(mice); ++j) {
|
|
DrawMouseState(window, renderer, &mice[j], arrow_cursor, &colors[j]);
|
|
}
|
|
|
|
for (j = 0; j < SDL_arraysize(keyboards); ++j) {
|
|
DrawKeyboardState(window, renderer, &keyboards[j], cross_cursor, &colors[j]);
|
|
}
|
|
|
|
SDL_RenderPresent(renderer);
|
|
}
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
int i;
|
|
|
|
/* Log all events, including mouse motion */
|
|
SDL_SetHint(SDL_HINT_EVENT_LOGGING, "2");
|
|
|
|
/* Support for multiple keyboards requires raw keyboard events on Windows */
|
|
SDL_SetHint(SDL_HINT_WINDOWS_RAW_KEYBOARD, "1");
|
|
|
|
/* Initialize test framework */
|
|
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
|
if (!state) {
|
|
return 1;
|
|
}
|
|
for (i = 1; i < argc;) {
|
|
int consumed;
|
|
|
|
consumed = SDLTest_CommonArg(state, i);
|
|
if (consumed < 0) {
|
|
SDLTest_CommonLogUsage(state, argv[0], NULL);
|
|
SDLTest_CommonQuit(state);
|
|
return 1;
|
|
}
|
|
i += consumed;
|
|
}
|
|
|
|
if (!SDLTest_CommonInit(state)) {
|
|
SDLTest_CommonQuit(state);
|
|
return 2;
|
|
}
|
|
|
|
/* Create the cursor textures */
|
|
for (i = 0; i < state->num_windows; ++i) {
|
|
SDL_Renderer *renderer = state->renderers[i];
|
|
SDL_Texture *cursor_arrow = CreateTexture(arrow, renderer);
|
|
SDL_Texture *cursor_cross = CreateTexture(cross, renderer);
|
|
|
|
SDL_SetPointerProperty(SDL_GetRendererProperties(renderer), PROP_ARROW_CURSOR_TEXTURE, cursor_arrow);
|
|
SDL_SetPointerProperty(SDL_GetRendererProperties(renderer), PROP_CROSS_CURSOR_TEXTURE, cursor_cross);
|
|
|
|
/* We only get mouse motion for distinct devices when relative mode is enabled */
|
|
SDL_SetWindowRelativeMouseMode(state->windows[i], true);
|
|
}
|
|
|
|
/* Main render loop */
|
|
done = 0;
|
|
while (!done) {
|
|
loop();
|
|
}
|
|
|
|
SDLTest_CommonQuit(state);
|
|
return 0;
|
|
}
|