Commit Graph
78 Commits
Author SHA1 Message Date
Nunuhara Cabbage eb8c7b0fe6 Move heap management code into heap.c 2019-12-23 16:53:00 -08:00
Nunuhara Cabbage 1db1a1cbc4 Return shift-jis from system.GetSaveFolderName 2019-12-22 11:02:36 -08:00
Nunuhara Cabbage a7b6ab6066 Implement system.MsgBox 2019-12-22 08:21:58 -08:00
Nunuhara Cabbage fd57ca7845 Fix loading of arrays
Array rank can't be inferred from JSON data since arrays and structs are
indistinguishable. So we get it from the ain file instead.

Sengoku Rance is mostly playable as of this commit.
2019-12-21 11:52:48 -08:00
Nunuhara Cabbage 6b16bd1b8e Implement A_REVERSE instruction 2019-12-21 07:19:38 -08:00
Nunuhara Cabbage a8d1abb483 Stubs for File.dll & ExistsFile syscalls 2019-12-21 07:07:34 -08:00
Nunuhara Cabbage 9b2b8965d9 Implement OBJSWAP instruction 2019-12-18 17:09:18 -08:00
Nunuhara Cabbage 0d0f89ad33 Track free address for HEAP_DEBUG
Useful for debugging double free errors.
2019-12-08 11:42:51 -08:00
Nunuhara Cabbage 1c0869b4fb Add debugger, run REPL on VM_ERROR
If Chibi-Scheme is installed, enable a debugger which can be used to
inspect the state of the VM when an error occurs.

So far only supports printing local/global variables. E.g.

    dbg> (print-variable "g_theSactMenu")
    ...
    dbg> (print-locals)
    ...
2019-12-07 09:24:38 -08:00
Nunuhara Cabbage 4c4833197a Implement STOI & FT_ASSIGNS instructions 2019-12-05 17:48:06 -08:00
Nunuhara Cabbage 92ff1195df Implement LI_* instructions (64-bit integers) 2019-12-04 21:28:03 -08:00
Nunuhara Cabbage 2d3bd9fff8 Handle SP_INC of NULL
'return NULL' generates an SP_INC instruction with -1 as its argument.
2019-12-04 20:13:13 -08:00
Nunuhara Cabbage 70b457d705 Load/Save from proper directory
The "SaveFolder" key in System40.ini gives the name of the save
directory. Earlier versions of system 4 treated this as a relative path
in the game directory, while later versions treated it as a path
relative to "$USER\My Documents\AliceSoft\$GAME_NAME". I've chosen the
latter approach, but using a xsystem4-specific directory to avoid
reading/overwriting saves created by System40.exe.
2019-12-04 16:55:48 -08:00
Nunuhara Cabbage a0826f69e4 Implement global save/load system calls
system.GlobalSave
system.GlobalLoad
system.GroupSave
system.GroupLoad

Save files are uncompressed JSON objects for now. Compatibility with
System40.exe saves would be nice, but the format appears to be
encrypted.

Minifying & compressing the JSON should be done at some point but for
debugging purposes I've left it totally uncompressed.

This commit also fixes a bunch of undefined behavior when assigning to
'heap[...]' with an rvalue that could initiate a realloc of the heap.
2019-12-03 22:54:41 -08:00
Nunuhara Cabbage c135c4cde7 Implement system.GetFuncStackName() 2019-12-01 22:04:09 -08:00
Nunuhara Cabbage 365df39093 Floating point assignment instructions 2019-12-01 17:44:14 -08:00
Nunuhara Cabbage 2778d2eb42 Add stubs for PlayMovie.dll 2019-12-01 17:43:30 -08:00
Nunuhara Cabbage b8fbba074b Add stubs for Confirm2.dll 2019-12-01 14:18:36 -08:00
Nunuhara Cabbage 61f0d61cbd Implement ITOLI instruction 2019-12-01 14:17:34 -08:00
Nunuhara Cabbage a02632590d Add stubs for AliceLogo*.dll 2019-12-01 11:05:14 -08:00
Nunuhara Cabbage 79dde45e44 Add stubs for SystemServiceEx.dll 2019-12-01 10:32:34 -08:00
Nunuhara Cabbage ce58a58c2c Improve readability of execute_instruction()
Use scopes in switch so that each case can have its own local variables.
2019-12-01 10:30:09 -08:00
Nunuhara Cabbage 91af527def Implement A_FIND instruction
This one is not supported by the SDK compiler, so no automated tests.
2019-11-30 15:47:06 -08:00
Nunuhara Cabbage b11319eb66 Initialize struct members with variable_initval
Fix bug where ref members were initialized to 0 instead of -1 (NULL).
2019-11-30 11:57:29 -08:00
Nunuhara Cabbage 4b158d3103 Don't assume 0() is last function
It's not always true that 0() is the last function in the ain file, so
it's necessary to store its index when loading the file.
2019-11-30 09:01:03 -08:00
Nunuhara Cabbage 6039ab9bd0 Fix multiple VM memory leaks
Also implement a feature to track leaked heap memory (DEBUG_HEAP).

With this, it is now possible to hold CTRL through the entire Rance II
digest version without crashing.
2019-11-27 18:11:07 -08:00
Nunuhara Cabbage a40467fe92 Allocate global structs before calling ctors
Global constructors can write to other global structs, so memory must be
allocated for all global structs before any constructors are called.
2019-11-25 18:40:49 -08:00
Nunuhara Cabbage 82d6f8c203 Use variable_initval to initialize globals
Fix bug where some globals weren't initialized
2019-11-25 15:39:19 -08:00
Nunuhara Cabbage 766f93407b Implement the DrawGraph.Copy* family of functions
Implement all of the simple copy functions, with the exception of
DrawGraph.CopyColorReverse, which is undocumented and appears to be dead
code (at least in the version of SACT2 that shipped with the SDK).
2019-11-25 12:19:14 -08:00
Nunuhara Cabbage 58f070dbb4 Partial implementation of ACXLoader.dll
Enough to read the acx files used by the Rance I/II digest versions.
2019-11-24 16:23:29 -08:00
Nunuhara Cabbage 029b013778 Call global constructors after setting initvals
Prevents clobbering of globals assigned in constructors.
2019-11-22 22:55:04 -08:00
Nunuhara Cabbage 2511a42378 Fix vm_time()
This code was clamping the timer between 0 and 1000 since the seconds
value was not used.
2019-11-22 22:45:20 -08:00
Nunuhara Cabbage e6f41f55b8 Implement S_LENGTH2 instruction 2019-11-19 21:23:12 -08:00
Nunuhara Cabbage 80ff1902e6 Implement MSG instruction 2019-11-19 20:34:31 -08:00
Nunuhara Cabbage 7ec7124d01 Implement CALLONJUMP and SJUMP instructions
Add support for scenario functions (functions which clear the call stack
upon entry and never return).
2019-11-19 19:56:18 -08:00
Nunuhara Cabbage 586a59d932 Call function "0" before main 2019-11-16 16:03:09 -08:00
Nunuhara Cabbage 6bfbce34b8 Add stubs for SACT2.Music_* 2019-11-16 14:51:45 -08:00
Nunuhara Cabbage 4a7075ffef Add stubs for MsgSkip.dll 2019-11-15 21:40:21 -08:00
Nunuhara Cabbage 0eefcaab36 Implement system.GetSaveFolderName() 2019-11-15 21:39:43 -08:00
Nunuhara Cabbage 89cee10c51 Implement system.GetTime() 2019-11-15 21:20:27 -08:00
Nunuhara Cabbage f4551005ba Add stubs for DrawPluginManager.dll 2019-11-15 19:49:51 -08:00
Nunuhara Cabbage 55fc577485 Add stubs for MsgLogManager.dll 2019-11-15 19:36:00 -08:00
Nunuhara Cabbage d3de009e1d Import CG reading code from xsystem35
Plus a bit of SACT2 implementation, and fix a bug where global arrays
were not initialized properly.
2019-11-15 19:01:08 -08:00
Nunuhara Cabbage e927f72905 SACT2.dll stubs 2019-11-10 16:24:37 -08:00
Nunuhara Cabbage c370e3eeaf Implement S_MOD (format strings)
Mostly relying on sprintf to do the work.
2019-11-10 13:44:01 -08:00
Nunuhara Cabbage ec9ab8954c Distinguish between global/local pages
Fix bug when calling variable_type on global variable (e.g. in A_ALLOC
on global).
2019-11-08 22:02:47 -08:00
Nunuhara Cabbage 1e3fbcd95f Change HLL calling convention
...and add OutputLog.dll stubs.

The calling convention no longer has HLL functions reaching into the
stack. The previous implementation didn't even work since the return
value could overwrite an argument that needed to be freed.
2019-11-07 19:26:58 -08:00
Nunuhara Cabbage 14dd027ef1 Initialize global structs 2019-11-04 21:47:36 -08:00
Nunuhara Cabbage edffc0ad76 Initial CALLHLL and Math.dll implementation
HLL libraries are compiled into the executable rather than dynamically
loaded as in early versions of System 4. These days AliceSoft does the
same thing.
2019-11-04 20:35:42 -08:00
Nunuhara Cabbage 9db69f8012 Implement DUP_U2, SP_INC, DELETE, R_ASSIGN
Reference assignment.
2019-10-31 21:37:47 -07:00