commit dd277bb41bea85b7d57a7d8fd50a8f3c6851414e
parent 7b24ddff03b0bc6265965c1addde29cd3c59bda8
Author: anon <anon@example.com>
Date: Fri, 16 Oct 2026 05:49:50 +0000
Fix native Linux startup in Lush Fields
Diffstat:
12 files changed, 221 insertions(+), 37 deletions(-)
diff --git a/src/Makefile.linux b/src/Makefile.linux
@@ -351,7 +351,7 @@ build/linux/cifmod: tests/cifmod.c runtime/guest_crt.c runtime/guest_heap.c runt
test: build/linux/cifmod
-build/linux/image-row: tests/image_row.c game/bbr.dll/lifted-0047.c runtime/guest_memory.c runtime/recomp_state.c runtime/recomp_types.h runtime/guest_memory.h
+build/linux/image-row: tests/image_row.c game/bbr.dll/lifted-0047.c game/kr.dll/lifted-0004.c runtime/guest_memory.c runtime/recomp_state.c runtime/recomp_types.h runtime/guest_memory.h
mkdir -p $(@D)
$(CC) $(CPPFLAGS) $(CFLAGS) -ffunction-sections $(filter %.c,$^) -Wl,--gc-sections -lm -o $@
diff --git a/src/game/kr.dll/lifted-0004.c b/src/game/kr.dll/lifted-0004.c
@@ -8774,13 +8774,13 @@ L_37012DB2:
if (2u) _cf = (((ecx) >> 1) & 1u); /* 0x37012DD6: shr ecx, 2 */
if (2u) { _flag_a = recomp_flags_pack((ecx >> 2u), _cf, 0, 0); _flag_b = 0; _flag_k = FK_EFLAGS; }
ecx = ecx >> 2u; /* 0x37012DD6: shr ecx, 2 */
- { uint32_t _n = ecx, _b = _n * 4u; /* 0x37012DD9: rep movsd dword ptr es:[edi], dword ptr [esi] */ if (_df > 0) { memmove((void*)ADDR(edi), (void*)ADDR(esi), _b); esi += _b; edi += _b; } else { memmove((void*)ADDR(edi - _b + 4u), (void*)ADDR(esi - _b + 4u), _b); esi -= _b; edi -= _b; } ecx = 0; }
+ { uint32_t _n = ecx, _b = _n * 4u; /* 0x37012DD9: rep movsd dword ptr es:[edi], dword ptr [esi] */ if (_n && _df > 0) { memmove((void*)ADDR(edi), (void*)ADDR(esi), _b); esi += _b; edi += _b; } else if (_n) { memmove((void*)ADDR(edi - _b + 4u), (void*)ADDR(esi - _b + 4u), _b); esi -= _b; edi -= _b; } ecx = 0; }
ecx = eax; /* 0x37012DDB: mov ecx, eax */
_flag_a = (uint32_t)(ecx); _flag_b = (uint32_t)(3);
ecx = ecx & 3; /* 0x37012DDD: and ecx, 3 */
_cf = 0;
_flag_k = FK_TEST;
- { uint32_t _n = ecx, _b = _n * 1u; /* 0x37012DE0: rep movsb byte ptr es:[edi], byte ptr [esi] */ if (_df > 0) { memmove((void*)ADDR(edi), (void*)ADDR(esi), _b); esi += _b; edi += _b; } else { memmove((void*)ADDR(edi - _b + 1u), (void*)ADDR(esi - _b + 1u), _b); esi -= _b; edi -= _b; } ecx = 0; }
+ { uint32_t _n = ecx, _b = _n * 1u; /* 0x37012DE0: rep movsb byte ptr es:[edi], byte ptr [esi] */ if (_n && _df > 0) { memmove((void*)ADDR(edi), (void*)ADDR(esi), _b); esi += _b; edi += _b; } else if (_n) { memmove((void*)ADDR(edi - _b + 1u), (void*)ADDR(esi - _b + 1u), _b); esi -= _b; edi -= _b; } ecx = 0; }
edi = POP32_VAL(esp); /* 0x37012DE2: pop edi */
esi = POP32_VAL(esp); /* 0x37012DE3: pop esi */
ebx = POP32_VAL(esp); /* 0x37012DE4: pop ebx */
@@ -8846,13 +8846,13 @@ L_37012E38:
if (2u) { _flag_a = recomp_flags_pack((ecx >> 2u), _cf, 0, 0); _flag_b = 0; _flag_k = FK_EFLAGS; }
ecx = ecx >> 2u; /* 0x37012E3F: shr ecx, 2 */
esi = edx; /* 0x37012E42: mov esi, edx */
- { uint32_t _n = ecx, _b = _n * 4u; /* 0x37012E44: rep movsd dword ptr es:[edi], dword ptr [esi] */ if (_df > 0) { memmove((void*)ADDR(edi), (void*)ADDR(esi), _b); esi += _b; edi += _b; } else { memmove((void*)ADDR(edi - _b + 4u), (void*)ADDR(esi - _b + 4u), _b); esi -= _b; edi -= _b; } ecx = 0; }
+ { uint32_t _n = ecx, _b = _n * 4u; /* 0x37012E44: rep movsd dword ptr es:[edi], dword ptr [esi] */ if (_n && _df > 0) { memmove((void*)ADDR(edi), (void*)ADDR(esi), _b); esi += _b; edi += _b; } else if (_n) { memmove((void*)ADDR(edi - _b + 4u), (void*)ADDR(esi - _b + 4u), _b); esi -= _b; edi -= _b; } ecx = 0; }
ecx = eax; /* 0x37012E46: mov ecx, eax */
_flag_a = (uint32_t)(ecx); _flag_b = (uint32_t)(3);
ecx = ecx & 3; /* 0x37012E48: and ecx, 3 */
_cf = 0;
_flag_k = FK_TEST;
- { uint32_t _n = ecx, _b = _n * 1u; /* 0x37012E4B: rep movsb byte ptr es:[edi], byte ptr [esi] */ if (_df > 0) { memmove((void*)ADDR(edi), (void*)ADDR(esi), _b); esi += _b; edi += _b; } else { memmove((void*)ADDR(edi - _b + 1u), (void*)ADDR(esi - _b + 1u), _b); esi -= _b; edi -= _b; } ecx = 0; }
+ { uint32_t _n = ecx, _b = _n * 1u; /* 0x37012E4B: rep movsb byte ptr es:[edi], byte ptr [esi] */ if (_n && _df > 0) { memmove((void*)ADDR(edi), (void*)ADDR(esi), _b); esi += _b; edi += _b; } else if (_n) { memmove((void*)ADDR(edi - _b + 1u), (void*)ADDR(esi - _b + 1u), _b); esi -= _b; edi -= _b; } ecx = 0; }
SET_LO8(ecx, MEM8(ebp + 0xF)); /* 0x37012E4D: mov cl, byte ptr [ebp + 0xf] */
L_37012E50:
esi = MEM32(ebp + 0x8); /* 0x37012E50: mov esi, dword ptr [ebp + 8] */
diff --git a/src/runtime/gl_renderer.c b/src/runtime/gl_renderer.c
@@ -315,7 +315,7 @@ void gl_target_clear_rect(struct gl_target *target, uint32_t flags, uint32_t arg
check_graphics("target clear");
}
-void gl_target_draw(struct gl_target *target, const struct gl_vertex *vertices,
+void gl_target_draw(struct gl_target *target, unsigned primitive, const struct gl_vertex *vertices,
unsigned vertex_count, const uint16_t *indices, unsigned index_count, const int32_t clip[4])
{
invalidate_mips(target);
@@ -347,11 +347,11 @@ void gl_target_draw(struct gl_target *target, const struct gl_vertex *vertices,
glBufferData(GL_ARRAY_BUFFER, vertex_count * sizeof(*vertices), vertices, GL_STREAM_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, index_count * sizeof(*indices), indices, GL_STREAM_DRAW);
- glDrawElements(GL_TRIANGLES, index_count, GL_UNSIGNED_SHORT, NULL);
+ glDrawElements(primitive == 2 ? GL_LINES : GL_TRIANGLES, index_count, GL_UNSIGNED_SHORT, NULL);
glDisable(GL_SCISSOR_TEST);
glBindVertexArray(0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
- check_graphics("indexed triangles");
+ check_graphics("indexed draw");
}
void gl_target_read(struct gl_target *target, unsigned char *rgba)
diff --git a/src/runtime/gl_renderer.h b/src/runtime/gl_renderer.h
@@ -32,8 +32,8 @@ void gl_depth_destroy(struct gl_depth *depth);
void gl_target_set_depth(struct gl_target *target, struct gl_depth *depth);
void gl_target_clear(struct gl_target *target, uint32_t argb, float depth);
void gl_target_clear_rect(struct gl_target *target, uint32_t flags, uint32_t argb, float depth, const int32_t rectangle[4]);
-/* Clip coordinates are guest top-down x, y, width, height. */
-void gl_target_draw(struct gl_target *target, const struct gl_vertex *vertices,
+/* Primitive is D3D line list (2) or triangle list (4); clip is guest top-down x, y, width, height. */
+void gl_target_draw(struct gl_target *target, unsigned primitive, const struct gl_vertex *vertices,
unsigned vertex_count, const uint16_t *indices, unsigned index_count, const int32_t clip[4]);
void gl_target_read(struct gl_target *target, unsigned char *rgba);
void gl_target_write(struct gl_target *target, const unsigned char *rgba);
diff --git a/src/runtime/linux_graphics.c b/src/runtime/linux_graphics.c
@@ -1756,16 +1756,16 @@ static void draw_primitive(struct device_object *device, uint32_t primitive, uin
{
unsigned texture_count = (fvf >> 8) & 15, format = fvf & ~0x300u;
int untransformed = texture_count >= 1 && (format == 0x12 || format == 0x52 || format == 0x42);
- if ((primitive != 4 && primitive != 5 && primitive != 6) || texture_count > 2 ||
+ if ((primitive != 2 && primitive != 4 && primitive != 5 && primitive != 6) || texture_count > 2 ||
(format != 0x44 && format != 0xc4 && !untransformed) || flags) {
fprintf(stderr, "Unsupported Direct3D draw primitive=%u fvf=%08x flags=%08x cull=%u\n", primitive, fvf, flags, device->cull); exit(3);
}
g_eax = 0x80070057u;
if (!input_indices) element_count = count;
- if (!input || !count || element_count < 3 || (primitive == 4 && element_count % 3) || count > 65535) return;
+ if (!input || !count || element_count < (primitive == 2 ? 2 : 3) || (primitive == 4 && element_count % 3) || count > 65535) return;
for (uint32_t i = 0; input_indices && i < element_count; ++i)
if (MEM16(input_indices + i * 2) >= count) return;
- uint32_t index_count = primitive == 4 ? element_count : (element_count - 2) * 3;
+ uint32_t index_count = primitive == 2 || primitive == 4 ? element_count : (element_count - 2) * 3;
struct gl_vertex *vertices = malloc(count * sizeof(*vertices));
uint16_t *indices = malloc(index_count * sizeof(*indices));
if (!vertices || !indices) abort();
@@ -1867,7 +1867,8 @@ static void draw_primitive(struct device_object *device, uint32_t primitive, uin
memcpy(uv, (void *)ADDR(input + i * stride + uv_offset + coordinate * 8), 8);
}
}
- if (primitive == 4) for (uint32_t i = 0; i < element_count; ++i) indices[i] = input_indices ? MEM16(input_indices + i * 2) : i;
+ /* Line and triangle lists retain their independent vertex groups. */
+ if (primitive == 2 || primitive == 4) for (uint32_t i = 0; i < element_count; ++i) indices[i] = input_indices ? MEM16(input_indices + i * 2) : i;
else for (uint32_t i = 0; i < element_count - 2; ++i) {
/* Fans share vertex zero; strips alternate winding for each triangle. */
uint32_t a = primitive == 6 ? 0 : i + (i & 1);
@@ -1894,7 +1895,7 @@ static void draw_primitive(struct device_object *device, uint32_t primitive, uin
gl_renderer_set_depth(device->depth_write, device->depth_function, device->depth_bias);
gl_renderer_set_cull(device->cull);
const int32_t clip[] = {device->viewport[0], device->viewport[1], device->viewport[2], device->viewport[3]};
- gl_target_draw(device->target->target, vertices, count, indices, index_count, clip);
+ gl_target_draw(device->target->target, primitive == 2 ? 2 : 4, vertices, count, indices, index_count, clip);
gl_renderer_set_blend(0, 2, 1);
gl_renderer_set_fog(0, 0);
for (unsigned stage = 0; stage < 2; ++stage) gl_renderer_set_texture(stage, NULL);
diff --git a/src/runtime/linux_imports.c b/src/runtime/linux_imports.c
@@ -178,6 +178,10 @@ recomp_func_t recomp_lookup_import(uint32_t va)
}
recomp_func_t function = linux_platform_lookup(imports[current_import].dll, imports[current_import].name);
if (function) return function;
+ if (!strcasecmp(imports[current_import].dll, "winmm.dll")) {
+ function = linux_thread_lookup(imports[current_import].name);
+ if (function) return function;
+ }
function = linux_window_lookup(imports[current_import].dll, imports[current_import].name);
if (function) return function;
if (!strcasecmp(imports[current_import].dll, "kernel32.dll")) {
diff --git a/src/runtime/linux_thread.c b/src/runtime/linux_thread.c
@@ -13,8 +13,9 @@ void recomp_eh_thread_exit(void);
* never terminates the thread; waits keep their own reference while blocked. */
struct guest_thread {
uint32_t handle, id, entry, argument, allocation, stack_size, exit_code;
+ uint32_t timer_delay;
unsigned references;
- int complete, suspended, automatic;
+ int complete, suspended, automatic, cancelled;
pthread_cond_t changed;
struct guest_thread *next;
};
@@ -64,7 +65,7 @@ static void finish_thread(void *argument)
check_pthread(pthread_mutex_lock(&mutex));
thread->complete = 1;
check_pthread(pthread_cond_broadcast(&thread->changed));
- if (thread->automatic) close_thread_locked(thread);
+ if (thread->automatic || thread->timer_delay) close_thread_locked(thread);
release_thread_locked(thread);
check_pthread(pthread_mutex_unlock(&mutex));
}
@@ -92,8 +93,33 @@ static void *run_thread(void *argument)
pthread_cleanup_push(finish_thread, thread);
linux_thread_notify(2); /* DLL_THREAD_ATTACH */
+ if (thread->timer_delay) {
+ /* A cancelled one-shot timer wakes without entering its guest callback. */
+ struct timespec deadline;
+ if (clock_gettime(CLOCK_MONOTONIC, &deadline)) abort();
+ deadline.tv_sec += thread->timer_delay / 1000;
+ deadline.tv_nsec += (thread->timer_delay % 1000) * 1000000;
+ if (deadline.tv_nsec >= 1000000000) { ++deadline.tv_sec; deadline.tv_nsec -= 1000000000; }
+ check_pthread(pthread_mutex_lock(&mutex));
+ int error = 0;
+ while (!thread->cancelled && error != ETIMEDOUT) {
+ error = pthread_cond_timedwait(&thread->changed, &mutex, &deadline);
+ if (error != ETIMEDOUT) check_pthread(error);
+ }
+ int cancelled = thread->cancelled;
+ check_pthread(pthread_mutex_unlock(&mutex));
+ if (cancelled) goto finished;
+ }
uint32_t stack = g_esp;
- PUSH32(g_esp, thread->argument);
+ if (thread->timer_delay) {
+ PUSH32(g_esp, 0); /* dw2 */
+ PUSH32(g_esp, 0); /* dw1 */
+ PUSH32(g_esp, thread->argument);
+ PUSH32(g_esp, 0); /* uMsg */
+ PUSH32(g_esp, thread->handle);
+ } else {
+ PUSH32(g_esp, thread->argument);
+ }
PUSH32(g_esp, RECOMP_RETADDR);
recomp_func_t entry = recomp_lookup(thread->entry);
if (!entry) {
@@ -106,13 +132,14 @@ static void *run_thread(void *argument)
fprintf(stderr, "Guest thread %08x returned with unbalanced stack\n", thread->entry);
abort();
}
- thread->exit_code = thread->automatic ? 0 : g_eax;
+ thread->exit_code = thread->automatic || thread->timer_delay ? 0 : g_eax;
+finished:
pthread_cleanup_pop(1);
return NULL;
}
static void create_thread(uint32_t stack_size, uint32_t entry, uint32_t argument,
- uint32_t flags, uint32_t id, int automatic)
+ uint32_t flags, uint32_t id, int automatic, uint32_t timer_delay)
{
g_eax = automatic ? UINT32_MAX : 0;
if (!entry) { MEM32(guest_crt_errno_address()) = 22; return; }
@@ -126,6 +153,7 @@ static void create_thread(uint32_t stack_size, uint32_t entry, uint32_t argument
if (!thread->allocation) { free(thread); MEM32(guest_crt_errno_address()) = 12; return; }
thread->entry = entry;
thread->argument = argument;
+ thread->timer_delay = timer_delay;
thread->stack_size = rounded;
/* Creation retains a reference even if an automatic thread exits immediately. */
thread->references = 3;
@@ -173,14 +201,44 @@ static void begin_thread(void)
abort();
}
g_esp += 4; /* _beginthreadex is cdecl; its entry function is stdcall. */
- create_thread(stack_size, entry, argument, flags, id, 0);
+ create_thread(stack_size, entry, argument, flags, id, 0, 0);
}
static void begin_automatic_thread(void)
{
uint32_t entry = MEM32(g_esp + 4), stack_size = MEM32(g_esp + 8), argument = MEM32(g_esp + 12);
g_esp += 4;
- create_thread(stack_size, entry, argument, 0, 0, 1);
+ create_thread(stack_size, entry, argument, 0, 0, 1, 0);
+}
+
+static void set_timer(void)
+{
+ uint32_t delay = MEM32(g_esp + 4), entry = MEM32(g_esp + 12);
+ uint32_t argument = MEM32(g_esp + 16), flags = MEM32(g_esp + 20);
+ g_esp += 24;
+ g_eax = 0;
+ if (flags) {
+ fprintf(stderr, "Unsupported multimedia timer flags %08x\n", flags);
+ exit(3);
+ }
+ if (!delay || !entry) return;
+ create_thread(0, entry, argument, 0, 0, 0, delay);
+}
+
+static void kill_timer(void)
+{
+ uint32_t handle = MEM32(g_esp + 4);
+ g_esp += 8;
+ g_eax = 11; /* MMSYSERR_INVALPARAM */
+ check_pthread(pthread_mutex_lock(&mutex));
+ for (struct guest_thread *thread = threads; thread; thread = thread->next) {
+ if (thread->handle != handle || !thread->timer_delay || thread->cancelled) continue;
+ thread->cancelled = 1;
+ check_pthread(pthread_cond_broadcast(&thread->changed));
+ g_eax = 0;
+ break;
+ }
+ check_pthread(pthread_mutex_unlock(&mutex));
}
static void end_thread(void)
@@ -266,6 +324,8 @@ static void resume_thread(void)
recomp_func_t linux_thread_lookup(const char *name)
{
+ if (!strcmp(name, "timeSetEvent")) return set_timer;
+ if (!strcmp(name, "timeKillEvent")) return kill_timer;
if (!strcmp(name, "_beginthreadex")) return begin_thread;
if (!strcmp(name, "_endthreadex")) return end_thread;
if (!strcmp(name, "_beginthread")) return begin_automatic_thread;
diff --git a/src/tests/devices.c b/src/tests/devices.c
@@ -564,6 +564,76 @@ static void indexed_vertex_buffers_use_relative_indices(uint32_t draw, uint32_t
invoke(d3d, 2, 1);
}
+static void line_lists_draw_independent_segments(uint32_t draw, uint32_t device, uint32_t target)
+{
+ const uint32_t iid[] = {0xf5049e77, 0x11d24861, 0xa00007a4, 0xa82906c9};
+ uint32_t d3d = query(draw, iid), desc = workspace() + 128, input = workspace() + 512;
+ const float identity[] = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1};
+ memcpy(memory(workspace() + 256), identity, 64);
+ for (unsigned transform = 1; transform <= 3; ++transform)
+ assert(!invoke(device, 11, 3, transform, workspace() + 256));
+ assert(!invoke(device, 20, 3, 137u, 0u));
+ assert(!invoke(device, 20, 3, 28u, 0u));
+ assert(!invoke(device, 20, 3, 29u, 0u));
+ assert(!invoke(device, 20, 3, 15u, 0u));
+ assert(!invoke(device, 20, 3, 27u, 0u));
+ assert(!invoke(device, 20, 3, 23u, 4u));
+ assert(!invoke(device, 35, 3, 0u, 0u));
+ assert(!invoke(device, 37, 4, 0u, 1u, 2u));
+ assert(!invoke(device, 37, 4, 0u, 2u, 0u));
+ assert(!invoke(device, 37, 4, 0u, 4u, 2u));
+ assert(!invoke(device, 37, 4, 0u, 5u, 0u));
+ assert(!invoke(device, 37, 4, 0u, 11u, 0u));
+ assert(!invoke(device, 37, 4, 0u, 24u, 0u));
+ assert(!invoke(device, 37, 4, 1u, 1u, 1u));
+
+ for (unsigned transformed = 0; transformed <= 1; ++transformed) {
+ unsigned stride = transformed ? 28 : 24;
+ uint32_t format = transformed ? 0x144 : 0x142;
+ const float positions[][4] = {{4,8,.25f,1}, {28,8,.25f,1}, {4,24,.25f,1}, {28,24,.25f,1}};
+ for (unsigned i = 0; i < 4; ++i) {
+ uint32_t vertex = input + i * stride;
+ if (transformed) memcpy(memory(vertex), positions[i], 16);
+ else {
+ float xyz[] = {positions[i][0] / 16 - 1, 1 - positions[i][1] / 16, .25f};
+ memcpy(memory(vertex), xyz, 12);
+ }
+ *memory(vertex + stride - 12) = 0xff5a96d2;
+ memset(memory(vertex + stride - 8), 0, 8);
+ }
+ uint32_t description[] = {16, 0x800, format, 6};
+ memcpy(memory(desc), description, 16);
+ assert(!invoke(d3d, 5, 4, desc, workspace(), 0u));
+ uint32_t buffer = *memory(workspace());
+ assert(!invoke(buffer, 3, 4, 0x1020u, workspace(), 0u));
+ memcpy(memory(*memory(workspace()) + 2 * stride), memory(input), 4 * stride);
+ assert(!invoke(buffer, 4, 1));
+ const uint16_t indices[] = {1, 0, 3, 2};
+ memcpy(memory(input + 128), indices, sizeof(indices));
+
+ for (unsigned path = 0; path < 3; ++path)
+ for (unsigned cull = 1; cull <= 3; ++cull) for (unsigned count = 2; count <= 4; count += 2) {
+ assert(!invoke(device, 10, 7, 0u, 0u, 3u, 0xff102030u, 0x3f800000u, 0u));
+ assert(!invoke(device, 20, 3, 22u, cull));
+ assert(!invoke(device, 5, 1));
+ if (path == 0) assert(!invoke(device, 25, 6, 2u, format, input, count, 0u));
+ else if (path == 1) assert(!invoke(device, 31, 6, 2u, buffer, 2u, count, 0u));
+ else assert(!invoke(device, 32, 8, 2u, buffer, 2u, count, input + 128, count, 0u));
+ assert(!invoke(device, 6, 1));
+
+ *memory(desc) = 124;
+ assert(!invoke(target, 25, 5, 0u, desc, 0x11u, 0u));
+ uint32_t pixels = *memory(desc + 36), pitch = *memory(desc + 16);
+ assert((*memory(pixels + 8 * pitch + 16 * 4) & 0xffffff) == 0x5a96d2);
+ assert((*memory(pixels + 16 * pitch + 16 * 4) & 0xffffff) == 0x102030);
+ assert((*memory(pixels + 24 * pitch + 16 * 4) & 0xffffff) == (count == 4 ? 0x5a96d2 : 0x102030));
+ assert(!invoke(target, 32, 2, 0u));
+ }
+ invoke(buffer, 2, 1);
+ }
+ invoke(d3d, 2, 1);
+}
+
static void untransformed_vertices_apply_camera_and_lighting(uint32_t device, uint32_t target, FILE *file)
{
for (unsigned emissive = 0; emissive < 3; ++emissive)
@@ -1454,6 +1524,7 @@ static void device_lifetime_and_rendering(const char *pixels_path)
depth_bias_offsets_overlapping_geometry(device, color, 24, file);
alpha_tests_preserve_rejected_color_and_depth(draw, device, color, file);
two_texture_stages_combine_independent_samples(draw, device, color, file);
+ line_lists_draw_independent_segments(draw, device, color);
assert(!fclose(file));
assert(!invoke(device, 2, 1));
assert(!invoke(draw, 2, 1));
@@ -1467,6 +1538,6 @@ int main(int argc, char **argv)
g_esp = 0x5000f000;
#endif
device_lifetime_and_rendering(argv[1]);
- puts("device: ownership, viewport, scenes, clear, triangles, depth, textures, filtering and blending passed");
+ puts("device: ownership, viewport, scenes, clear, triangles, line lists, depth, textures, filtering and blending passed");
return 0;
}
diff --git a/src/tests/graphics.c b/src/tests/graphics.c
@@ -606,17 +606,17 @@ static void attached_depth_is_shared_and_retained(void)
const uint16_t indices[] = {0, 1, 2};
unsigned char pixels[32 * 32 * 4];
- gl_target_draw(first, vertices, 3, indices, 3, (const int32_t[]){0, 0, 32, 32});
+ gl_target_draw(first, 4, vertices, 3, indices, 3, (const int32_t[]){0, 0, 32, 32});
gl_target_set_depth(first, NULL);
gl_target_destroy(first);
for (unsigned i = 0; i < 3; ++i) vertices[i].position[2] = 0.75f;
- gl_target_draw(second, vertices, 3, indices, 3, (const int32_t[]){0, 0, 32, 32});
+ gl_target_draw(second, 4, vertices, 3, indices, 3, (const int32_t[]){0, 0, 32, 32});
gl_target_read(second, pixels);
unsigned center = (16 * 32 + 16) * 4;
assert(pixels[center] == 0 && pixels[center + 1] == 0 && pixels[center + 2] == 255);
gl_target_set_depth(second, NULL);
- gl_target_draw(second, vertices, 3, indices, 3, (const int32_t[]){0, 0, 32, 32});
+ gl_target_draw(second, 4, vertices, 3, indices, 3, (const int32_t[]){0, 0, 32, 32});
gl_target_read(second, pixels);
assert(pixels[center] == 255 && pixels[center + 1] == 255 && pixels[center + 2] == 255);
gl_target_destroy(second);
@@ -638,7 +638,7 @@ static void uploads_preserve_depth_and_top_down_pixels(void)
unsigned char output[16];
gl_target_write(target, input);
- gl_target_draw(target, vertices, 3, indices, 3, (const int32_t[]){0, 0, 2, 2});
+ gl_target_draw(target, 4, vertices, 3, indices, 3, (const int32_t[]){0, 0, 2, 2});
gl_target_read(target, output);
assert(!memcmp(input, output, sizeof(input)));
@@ -658,14 +658,14 @@ static void indexed_triangles_preserve_depth_and_target_contents(void)
unsigned char pixels[32 * 32 * 4];
gl_target_clear(first, 0xff102030u, 1.0f);
- gl_target_draw(first, vertices, 3, indices, 3, (const int32_t[]){0, 0, 32, 32});
+ gl_target_draw(first, 4, vertices, 3, indices, 3, (const int32_t[]){0, 0, 32, 32});
gl_target_clear(second, 0xff405060u, 1.0f);
for (unsigned i = 0; i < 3; ++i) {
vertices[i].position[2] = 0.75f;
vertices[i].color[0] = 1;
vertices[i].color[1] = 0;
}
- gl_target_draw(first, vertices, 3, indices, 3, (const int32_t[]){0, 0, 32, 32});
+ gl_target_draw(first, 4, vertices, 3, indices, 3, (const int32_t[]){0, 0, 32, 32});
gl_target_read(first, pixels);
const unsigned center = (16 * 32 + 16) * 4;
@@ -677,12 +677,12 @@ static void indexed_triangles_preserve_depth_and_target_contents(void)
gl_target_read(second, pixels);
assert(pixels[center] == 64 && pixels[center + 1] == 80 && pixels[center + 2] == 96 && pixels[center + 3] == 255);
gl_target_clear(first, 0xff102030u, 0.0f);
- gl_target_draw(first, vertices, 3, indices, 3, (const int32_t[]){0, 0, 32, 32});
+ gl_target_draw(first, 4, vertices, 3, indices, 3, (const int32_t[]){0, 0, 32, 32});
gl_target_read(first, pixels);
assert(pixels[center] == 16 && pixels[center + 1] == 32 && pixels[center + 2] == 48);
gl_target_clear(first, 0xff102030u, 1.0f);
for (unsigned i = 0; i < 3; ++i) vertices[i].position[2] = -0.25f;
- gl_target_draw(first, vertices, 3, indices, 3, (const int32_t[]){0, 0, 32, 32});
+ gl_target_draw(first, 4, vertices, 3, indices, 3, (const int32_t[]){0, 0, 32, 32});
gl_target_read(first, pixels);
assert(pixels[center] == 16 && pixels[center + 1] == 32 && pixels[center + 2] == 48);
struct gl_vertex gradient[] = {
@@ -691,17 +691,17 @@ static void indexed_triangles_preserve_depth_and_target_contents(void)
{{-1, 1, 0.25f, 1}, {0, 0, 1, 1}}
};
const uint16_t reversed[] = {0, 2, 1};
- gl_target_draw(first, gradient, 3, reversed, 3, (const int32_t[]){0, 0, 32, 32});
+ gl_target_draw(first, 4, gradient, 3, reversed, 3, (const int32_t[]){0, 0, 32, 32});
gl_target_read(first, pixels);
unsigned sample = (24 * 32 + 8) * 4;
assert((pixels[sample] == 127 || pixels[sample] == 128) && pixels[sample + 1] == 68 && pixels[sample + 2] == 60);
for (unsigned i = 0; i < 4; ++i) gradient[1].position[i] *= 2;
- gl_target_draw(first, gradient, 3, reversed, 3, (const int32_t[]){0, 0, 32, 32});
+ gl_target_draw(first, 4, gradient, 3, reversed, 3, (const int32_t[]){0, 0, 32, 32});
gl_target_read(first, pixels);
assert(pixels[sample] == 147 && pixels[sample + 1] == 39 && pixels[sample + 2] == 69);
gl_target_clear(first, 0xff102030u, 1.0f);
for (unsigned i = 0; i < 3; ++i) vertices[i].position[2] = 1.25f;
- gl_target_draw(first, vertices, 3, indices, 3, (const int32_t[]){0, 0, 32, 32});
+ gl_target_draw(first, 4, vertices, 3, indices, 3, (const int32_t[]){0, 0, 32, 32});
gl_target_read(first, pixels);
assert(pixels[center] == 16 && pixels[center + 1] == 32 && pixels[center + 2] == 48);
gl_target_destroy(first);
diff --git a/src/tests/image_row.c b/src/tests/image_row.c
@@ -5,6 +5,7 @@
#endif
void sub_250CB6E0(void);
+void sub_37012DA0(void);
recomp_func_t recomp_lookup(uint32_t address) { abort(); }
recomp_func_t recomp_lookup_import(uint32_t address) { abort(); }
recomp_func_t recomp_lookup_manual(uint32_t address) { abort(); }
@@ -20,6 +21,7 @@ int main(void)
#endif
}
const unsigned lengths[] = {0, 1, 2, 3, 4, 7, 8, 2048};
+ for (unsigned decoder = 0; decoder < 2; ++decoder)
for (unsigned i = 0; i < sizeof(lengths) / sizeof(lengths[0]); ++i) {
unsigned length = lengths[i];
uint32_t input = 0x50010000 - length, output = 0x51010000 - length;
@@ -34,12 +36,13 @@ int main(void)
MEM32(g_esp + 12) = 255;
g_ebx = 123; g_esi = 234; g_edi = 345; g_ebp = 456;
- sub_250CB6E0();
+ if (decoder == 0) sub_250CB6E0();
+ else sub_37012DA0();
assert(g_esp == 0x5300ff04);
assert(g_ebx == 123 && g_esi == 234 && g_edi == 345 && g_ebp == 456);
for (unsigned j = 0; j < length; ++j) assert(MEM8(output + j) == (unsigned char)(j * 13 + 7));
assert(MEM8(output - 1) == 0xa5);
}
- puts("image row: 8 boundary-ending copies, including zero length; bytes, canaries and ABI passed");
+ puts("image row: 2 decoders, 8 boundary-ending copies each, including zero length; bytes, canaries and ABI passed");
}
diff --git a/src/tests/threads.c b/src/tests/threads.c
@@ -23,6 +23,7 @@ static unsigned counter;
#include <stdatomic.h>
static pthread_barrier_t cpu_barrier;
static _Atomic unsigned attached, detached;
+static _Atomic unsigned timer_calls, timer_id, timer_user;
static _Thread_local int notified;
void sub_42001000(void);
void sub_42001100(void);
@@ -290,11 +291,22 @@ static void exiting_entry(void)
call(linux_thread_lookup("_endthreadex"), 1, &code, 1);
abort();
}
+static void timer_entry(void)
+{
+ assert(notified && !tls_get());
+ assert(!MEM32(g_esp + 8) && !MEM32(g_esp + 16) && !MEM32(g_esp + 20));
+ timer_id = MEM32(g_esp + 4);
+ timer_user = MEM32(g_esp + 12);
+ ++timer_calls;
+ signal_semaphore(done, 1);
+ g_esp += 24;
+}
recomp_func_t recomp_lookup(uint32_t address)
{
if (address == 0x11001000) return returning_entry;
if (address == 0x11002000) return exiting_entry;
if (address == 0x11003000) return automatic_entry;
+ if (address == 0x11004000) return timer_entry;
if (address == 0x42001000) return sub_42001000;
if (address == 0x42001100) return sub_42001100;
if (address == 0x42002000) return native32_shim_CxxThrowException;
@@ -405,6 +417,37 @@ static void automatic_thread_closes_its_handle(uint32_t mode)
assert(!open && tls_get() == 0xabcdef01);
}
+#ifndef _WIN32
+static void one_shot_timer_calls_guest_callback_once(void)
+{
+ recomp_func_t set = linux_thread_lookup("timeSetEvent"), kill = linux_thread_lookup("timeKillEvent");
+ assert(set && kill);
+ uint32_t arguments[] = {20, 0, 0x11004000, 0x12345678, 0};
+
+ uint32_t timer = call(set, 5, arguments, 0);
+ assert(timer && !wait(done, 1000, 0));
+ uint32_t delay = 50;
+ call(linux_platform_lookup("kernel32.dll", "Sleep"), 1, &delay, 0);
+
+ assert(timer_calls == 1 && timer_id == timer && timer_user == 0x12345678);
+ assert(tls_get() == 0xabcdef01);
+ assert(call(kill, 1, &timer, 0) == 11);
+}
+
+static void cancelled_timer_does_not_call_guest_callback(void)
+{
+ uint32_t arguments[] = {100, 0, 0x11004000, 0xabcdef, 0};
+ uint32_t timer = call(linux_thread_lookup("timeSetEvent"), 5, arguments, 0);
+ assert(timer);
+
+ uint32_t result = call(linux_thread_lookup("timeKillEvent"), 1, &timer, 0);
+
+ assert(!result && wait(done, 200, 0) == 258);
+ assert(timer_calls == 1);
+ assert(call(linux_thread_lookup("timeKillEvent"), 1, &timer, 0) == 11);
+}
+#endif
+
int main(void)
{
#ifdef _WIN32
@@ -453,6 +496,8 @@ int main(void)
call(linux_platform_lookup("kernel32.dll", "Sleep"), 1, &delay, 0);
}
assert(attached == 38 && detached == 38);
+ one_shot_timer_calls_guest_callback_once();
+ cancelled_timer_does_not_call_guest_callback();
assert(!pthread_barrier_destroy(&cpu_barrier));
assert(call(linux_tls_lookup("TlsFree"), 1, &tls_index, 0));
call(linux_platform_lookup("kernel32.dll", "DeleteCriticalSection"), 1, §ion, 0);
diff --git a/tools/client/test_portable_image_row.py b/tools/client/test_portable_image_row.py
@@ -11,7 +11,7 @@ reference = work / "reference.exe"
subprocess.run([
str(root / "toolchains/llvm-mingw-20261006-ucrt-x86_64/bin/i686-w64-mingw32-clang.exe"),
"-O2", "-Iruntime", "-ffunction-sections", "-fno-strict-aliasing", "tests/image_row.c",
- "game/bbr.dll/lifted-0047.c", "runtime/recomp_state.c", "-Wl,--gc-sections", "-o", str(reference),
+ "game/bbr.dll/lifted-0047.c", "game/kr.dll/lifted-0004.c", "runtime/recomp_state.c", "-Wl,--gc-sections", "-o", str(reference),
], cwd=decompiled, check=True)
expected = subprocess.check_output([str(reference)], text=True, timeout=30)
linux_path = "/mnt/" + decompiled.drive[0].lower() + decompiled.as_posix()[2:]