Commit Graph
998 Commits
Author SHA1 Message Date
Nunuhara Cabbage 61097cfe73 aindump: option to check xsystem4 compatibility
Add -A,--audit option to check an ain file's compatibility with
xsystem4. Currently only checks for unimplemented instructions and
syscalls.
2020-01-09 19:10:06 -08:00
Nunuhara Cabbage e00501346b Fix LI_* instructions
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.
2020-01-08 19:14:08 -08:00
Nunuhara Cabbage 6a4d11f3de Use libffi for library calls
Use libffi to portably call arbitrary functions at runtime, rather than
forcing library functions to use a standard prototype.
2020-01-07 22:48:29 -08:00
Nunuhara Cabbage f1cc9082b3 Don't store HLL function pointers in ain struct
Store them in vm.c. The ain structure should not contain data that
wasn't in the ain file on disk.
2020-01-03 18:48:30 -08:00
Nunuhara Cabbage 3221f4a735 aindump: improve command line interface
Allow specifying output file with -o, and make more mnemonic short
options by using upper case letters when the lower case is already
taken.
2020-01-02 17:43:06 -08:00
Nunuhara Cabbage 03e9d59825 aindump: improve disassembler output
Replace many instruction arguments with names/values (strings/messages,
local/global variables, structs, functions, etc.) and add labels to jump
targets.
2020-01-01 20:34:35 -08:00
Nunuhara Cabbage f272f807e1 Fix long int truncation in assignment instructions 2019-12-31 22:05:30 -08: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
Nunuhara Cabbage 9b865d15fe Implement crossfade effect 2019-12-30 18:30:39 -08:00
Nunuhara Cabbage ccc367ec12 Basic audio support
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).
2019-12-29 12:05:09 -08:00
Nunuhara Cabbage 88395ada63 Call object destructors on deletion 2019-12-27 13:17:22 -08:00
Nunuhara Cabbage f903fc1712 Fix bug in A_SORT
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.
2019-12-26 14:43:12 -08:00
Nunuhara Cabbage c60e804420 tmp 2019-12-26 13:11:47 -08:00
Nunuhara Cabbage 5da0916472 Implement system.ResumeSave/system.ResumeLoad
Save/load VM images as JSON.
2019-12-25 22:28:39 -08:00
Nunuhara Cabbage 084634c2fc Fix multiple memory leaks 2019-12-25 22:23:20 -08:00
Nunuhara Cabbage eb8c7b0fe6 Move heap management code into heap.c 2019-12-23 16:53:00 -08:00
Nunuhara Cabbage 9bb1d0ec0b Implement ACXLoader.GetDataInt 2019-12-22 14:29:12 -08:00
Nunuhara Cabbage 77d62d517a Implement File.{Open,Close,Read,Write}
Alternate method of saving data. I'm guessing this was superceded by
system.GroupSave/GroupLoad.
2019-12-22 14:26:09 -08:00
Nunuhara Cabbage df4656e929 Create save folder on startup 2019-12-22 14:24:09 -08:00
Nunuhara Cabbage d7ca25ade8 Free CG in SACT2.SetWP 2019-12-22 13:02:04 -08:00
Nunuhara Cabbage 1db1a1cbc4 Return shift-jis from system.GetSaveFolderName 2019-12-22 11:02:36 -08:00
Nunuhara Cabbage 83e052c81b Implement SACT2.SetWP & SACT2.SetWP_Color 2019-12-22 10:27:31 -08:00
Nunuhara Cabbage 2811942de8 Implement SACT2.SP_Count & SACT2.SP_Enum 2019-12-22 09:32:45 -08:00
Nunuhara Cabbage 096b192c73 Implement SACT2.System_GetTime/System_GetDate 2019-12-22 08:44:01 -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 dd77689199 Implement DrawGraph.DrawTextToPMap & others
DrawGraph.GetPixelColor
DrawGraph.GetAlphaColor
SACT2.SP_GetAMapValue
SACT2.SP_GetPixelValue
2019-12-21 07:06:52 -08:00
Nunuhara Cabbage 6bef461a5d Implement SACT2.GetMainSurfaceNumber
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.
2019-12-20 20:18:17 -08:00
Nunuhara Cabbage 5acf0a6e4c Partial implementation of DrawGraph text functions 2019-12-20 19:42:56 -08:00
Nunuhara Cabbage 9b2b8965d9 Implement OBJSWAP instruction 2019-12-18 17:09:18 -08:00
Nunuhara Cabbage b12cce78e1 Implement DrawGraph.CopyRotZoom* functions 2019-12-18 17:08:14 -08:00
Nunuhara Cabbage e90821cc20 Use OpenGL instead of SDL's 2D graphics API
This will be necessary for supporting 3D games in the future (Rance VI,
GALZOO, etc.).
2019-12-16 19:59:17 -08:00
Nunuhara Cabbage 91c84e9988 Implement DrawGraph.BlendAMapAlpha 2019-12-09 15:08:30 -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 430c6fbbb6 Handle reference types in array_type()
When allocating an array through a reference variable, the reference
type is passed to the array_* functions rather than the bare array type.
2019-12-08 11:39:29 -08:00
Nunuhara Cabbage 673d762769 Properly implement SACT2.SetBlendRate/GetBlendRate
The blend rate is independent of the alpha value used when creating a
filled rectangle with SP_CREATE.
2019-12-08 08:18:58 -08:00
Nunuhara Cabbage ba6e6b33dd Fix buffer overflows 2019-12-07 14:16:53 -08:00
Nunuhara Cabbage c09e4b6601 Improve text rendering
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.
2019-12-07 14:06:37 -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 b6fbd36fef Implement various DrawGraph functions
Enough to get to the first battle in Sengoku Rance.
2019-12-05 17:49:21 -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 13eefac0ac Fix multiple memory issues with the help of asan
Fix buffer overflows and memory leaks.
2019-12-04 20:53:56 -08:00
Nunuhara Cabbage c593229f03 Call handle_events() from SACT2.Key_IsDown
This function can be called in a loop without any SACT2.Update calls.
2019-12-04 20:13:51 -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 1e01e1e5a7 Implement SACT2.SP_IsPtIn 2019-12-04 17:23:52 -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