Commit Graph
13 Commits
Author SHA1 Message Date
Nunuhara Cabbage 4b1257fc13 Fix delegate memory management
Although delegate pages store references to objects on the heap,
adding/removing objects from a delegate does not affect their reference
counts. When an object that is a member of a delegate is deleted, it is
automatically removed from the delegate.

In practice, this means that every object needs to keep a list of
delegates that it belongs to. This increases the size of the page header
on 64 bit systems, but not by much since the additional metadata can be
stored in a union with the array-specific metadata.
2023-04-13 16:38:13 -07:00
Nunuhara Cabbage 3e536af09a Implement DG_ADD, DG_EXIST, DG_ERASE 2022-08-02 18:16:16 -07:00
Nunuhara Cabbage 73b21210c2 Fix delegate memory management issues
Delegates should be ref'd in vm_copy and unref'd in variable_fini.

This also includes some improvements to the diagnostic reporting of
DEBUG_HEAP.
2022-06-26 17:55:05 -07:00
Nunuhara Cabbage 6f750e4007 More delegate fixes
1. DG_CALL has to clean up the stack before jumping to the return
   address.
2. DG_SET (contrary to its name) is an append operation; it's basically
   a combination of DG_NEW_FROM_METHOD and DG_PLUSA.
3. DG_SET and DG_PLUSA need to check for and ignore duplicates.
4. Delegate pages store *references* to structs; the VM should NOT copy
   the struct page when copying a delegate page.
2022-01-29 09:55:42 -08:00
Nunuhara Cabbage b7aaa1897b Implement A_SORT_MEM
Sorts an array of structs by a given member.
2022-01-23 15:11:48 -08:00
Nunuhara Cabbage 5ff042738e Initial delegates implementation
This isn't very well tested yet, but it runs Rance 01 up to the first
HLL error.
2021-10-18 10:45:10 -07:00
Nunuhara Cabbage 10d838ebc4 Fix bug when loading heap
Need to grow as needed.
2021-05-12 19:36:48 -07:00
Nunuhara Cabbage 2365fb3a01 Implement various SH_ instructions
Implement various shorthand instructions introduced in Alice 2010. This
is enough to get through the first scene in Haru Urare.
2021-05-09 20:53:32 -07:00
Nunuhara Cabbage 49458585d6 Implement ADVSceneKeeper functions
This is a serialization interface for a particular struct type. I've
implemented it somewhat generically, only checking that the name of the
struct matches the expected type. The actual structure of the objects
passed in is not checked, and in fact this structure differs between
games.

The serialized data produced by ADVSceneKeeper.Save should be identical
to what's produced by AnteaterADVEngine.dll from Shaman's Sanctuary.
2021-05-08 10:52:47 -07:00
Nunuhara Cabbage 851a19acc1 Work around for FFI heap reallocation bugs
ref types are currently passed to HLL functions as pointers into the
heap. If the HLL function itself needs to allocate memory from the heap,
it can cause the heap to be reallocated, rendering these heap pointers
invalid.

In order to work around this, hll_call now guarantees 64 slots are
available on the heap before calling any HLL function. This is not a
great solution, but it should work to the extent that HLL functions only
allocate a fixed number of heap slots < 64.

This bug could be easily triggered by scrolling up on the message log in
Sengoku Rance.
2021-02-20 20:41:05 -08:00
Nunuhara Cabbage a901404d3c Declare global variables extern in headers
Recent versions of gcc seem to emit symbols for unadorned declarations,
leading to linker errors.
2020-09-03 10:15:25 -07:00
Nunuhara Cabbage 2813767648 Fix memory leaks in A_PUSHBACK and A_FILL 2020-08-23 12:52:19 -07:00
Nunuhara Cabbage 5d6f148e1b Reorganize project file structure
- Create separate directories for source and header files.
- Build code shared between xsystem4 and aindump as a static library.
- Create header dirs gfx/ system4/ and vm/
- Make CG.c/h usable without a running VM
2019-12-31 17:50:40 -08:00