diff --git a/binding-sandbox/binding-base.h b/binding-sandbox/binding-base.h index 5cc59440..1ccd88a2 100644 --- a/binding-sandbox/binding-base.h +++ b/binding-sandbox/binding-base.h @@ -289,7 +289,13 @@ namespace mkxp_sandbox { fiber->stack.pop_back(); } ++fiber->stack_index; - b.stack_ptr = w2c_ruby_rb_wasm_get_stack_pointer(&b.instance()) - CEIL_WASMSTACKALIGN(declared_slots_size::value); + b.stack_ptr = w2c_ruby_rb_wasm_get_stack_pointer(&b.instance()) +#ifdef MKXPZ_BIG_ENDIAN + + +#else + - +#endif // MKXPZ_BIG_ENDIAN + CEIL_WASMSTACKALIGN(declared_slots_size::value); assert(b.stack_ptr % sizeof(VALUE) == 0); assert(b.stack_ptr % WASMSTACKALIGN == 0); if (declared_slots_size::value != 0) { @@ -333,7 +339,16 @@ namespace mkxp_sandbox { assert(fiber->stack.size() == fiber->stack_index); - w2c_ruby_rb_wasm_set_stack_pointer(&bind->instance(), fiber->stack.back().stack_ptr + CEIL_WASMSTACKALIGN(declared_slots_size::value)); + w2c_ruby_rb_wasm_set_stack_pointer( + &bind->instance(), + fiber->stack.back().stack_ptr +#ifdef MKXPZ_BIG_ENDIAN + - +#else + + +#endif // MKXPZ_BIG_ENDIAN + CEIL_WASMSTACKALIGN(declared_slots_size::value) + ); bind->stack_ptr = fiber->stack.back().stack_ptr; fiber->stack.pop_back(); } diff --git a/libretro/sandbox-bindgen.rb b/libretro/sandbox-bindgen.rb index 95fbe246..0dedece6 100644 --- a/libretro/sandbox-bindgen.rb +++ b/libretro/sandbox-bindgen.rb @@ -269,6 +269,16 @@ PRELUDE = <<~HEREDOC bindings::bindings(std::shared_ptr m) : binding_base(m) {} + static wasm_ptr_t _sbindgen_stack_push(wasm_ptr_t frame_pointer, wasm_size_t num_bytes) { + return frame_pointer + #ifdef MKXPZ_BIG_ENDIAN + + + #else + - + #endif // MKXPZ_BIG_ENDIAN + num_bytes; + } + static void _sbindgen_strcpy(char *dst, const char *src) { #ifdef MKXPZ_BIG_ENDIAN do { @@ -512,7 +522,7 @@ File.readlines('tags', chomp: true).each do |line| coroutine_initializer += <<~HEREDOC { wasm_ptr_t fp = w2c_ruby_rb_wasm_get_stack_pointer(&bind.instance()); - wasm_ptr_t sp = fp - CEIL_WASMSTACKALIGN(a#{args.length - 2} * sizeof(VALUE)); + wasm_ptr_t sp = _sbindgen_stack_push(fp, CEIL_WASMSTACKALIGN(a#{args.length - 2} * sizeof(VALUE))); if (sp > fp) { throw std::bad_alloc(); } @@ -539,7 +549,7 @@ File.readlines('tags', chomp: true).each do |line| do ++n; while (va_arg(b, VALUE)); va_end(b); wasm_ptr_t fp = w2c_ruby_rb_wasm_get_stack_pointer(&bind.instance()); - wasm_ptr_t sp = fp - CEIL_WASMSTACKALIGN(n * sizeof(VALUE)); + wasm_ptr_t sp = _sbindgen_stack_push(fp, CEIL_WASMSTACKALIGN(n * sizeof(VALUE))); if (sp > fp) { throw std::bad_alloc(); } diff --git a/src/display/bitmap.cpp b/src/display/bitmap.cpp index 991bdebf..85de7c73 100644 --- a/src/display/bitmap.cpp +++ b/src/display/bitmap.cpp @@ -1979,7 +1979,7 @@ void Bitmap::replaceRaw(void *pixel_data, int size) throw Exception(Exception::MKXPError, "Replacement bitmap data is not large enough (given %i bytes, need %i)", size, requiredsize); #if defined(MKXPZ_RETRO) && defined(MKXPZ_BIG_ENDIAN) - output -= output_size; + pixel_data -= output_size; std::reverse((uint8_t *)pixel_data, (uint8_t *)pixel_data + size); #endif