The 'lint' type in system 4 is NOT a 64-bit integer type. It is actually
a signed 32-bit integer type that is clamped between 0 and INT32_MAX.
Negative numbers can be assigned to a lint using SH_LOCALASSIGN (or at
least, the unofficial compiler emits such code) but LI_* instructions
always produce a positive result.
I'm guessing System40.exe converts lints to 64-bit integers for doing
arithmetic, and then clamps the result to the 32-bit integer range
before writing back to a variable.
This fixes a bug in Sengoku Rance where units would become invincible in
commander battles after their HP fell below zero.
Replace many instruction arguments with names/values (strings/messages,
local/global variables, structs, functions, etc.) and add labels to jump
targets.
- 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
This covers enough of the music/sound functions to get the few games I
tried working.
Looping is not properly implemented here. Unfortunately, loop offsets
are stored in a "bgi" file which appears to be encypted. There are two
options for fixing this: (1) the proper solution, crack the bgi
encryption and read the offsets from that file, or (2) read the loop
offsets from the "smpl" chunk in the wav file. (2) is easier but it will
only work for wav files (not ogg).
Swap order of arguments in call to qsort.
Also modify array_* interfaces so that they do not take pointers into
the heap. Passing around pointers into the heap is dangerous since it
can be reallocated at unexpected times.
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.
Sprites are now rendered to an off-screen texture which is then rendered
to the screen in gfx_swap. The sprite table in sact_graphics is set up
so that sprites[-1] provides access to this off-screen texture.
Sengoku Rance uses 1400 and 1700 for FW_NORMAL and FW_BOLD rather that
400 and 700.
Text surfaces now have a transparent white background instead of a
transparent black background. This looks better in SR since it uses a
lot of white text/white outlines. The underlying problem is that the
color value of completely transparent pixels is blended with the glyph
color when blitting to the text surface.
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)
...
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.
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.