Run the original macOS ARM64 game code on iOS: - tools/retarget.py: header-only Mach-O retargeting to an iOS dylib - platform/native: UIKit host and macOS API shims (AppKit for SDL's Cocoa backend, CoreGraphics displays, CoreAudio device, Metal device properties, Wuffs PNG decoding, Steam and peripheral stubs) - touch, overlay, iOS keyboard and hardware keyboard input - tools/build_native.py: build, sign, install, data copy, launch - docs: build guide, controls, architecture Also includes the earlier static-translation research (ARM64 -> WASM -> native) under docs/research, runtime/, tests/ and tools/. No game files are included; the build reads them from a local install.
27 lines
1.1 KiB
C
27 lines
1.1 KiB
C
#include "guest_heap.h"
|
|
#include <limits.h>
|
|
|
|
int factorio_guest_heap_init(FactorioGuestHeap *heap, uint8_t *memory,
|
|
uint64_t memory_size, uint64_t begin, uint64_t end) {
|
|
if (!heap || !memory || !begin || begin > end || end > memory_size ||
|
|
memory_size > SIZE_MAX || begin % 16) return 2;
|
|
*heap = (FactorioGuestHeap){memory, memory_size, begin, begin, end, 0};
|
|
return 0;
|
|
}
|
|
|
|
int factorio_guest_heap_allocate(FactorioGuestHeap *heap, uint64_t size, uint64_t *out) {
|
|
if (!heap || !out || !heap->memory || !heap->begin || heap->begin % 16 ||
|
|
heap->cursor < heap->begin || heap->cursor > heap->end ||
|
|
heap->end > heap->memory_size || heap->memory_size > SIZE_MAX ||
|
|
heap->allocations == UINT_MAX) return 2;
|
|
uint64_t padding = (16 - heap->cursor % 16) % 16;
|
|
if (padding > heap->end - heap->cursor) return 1;
|
|
uint64_t address = heap->cursor + padding;
|
|
if (!size) size = 1; /* operator new(0) still returns a distinct allocation. */
|
|
if (size > heap->end - address) return 1;
|
|
heap->cursor = address + size;
|
|
++heap->allocations;
|
|
*out = address;
|
|
return 0;
|
|
}
|