Commit Graph
156 Commits
Author SHA1 Message Date
Nunuhara Cabbage 4e6bf60e1b aindump: quote identifiers containing spaces
...so that they can be reliably parsed.
2020-01-11 21:24:53 -08:00
Nunuhara Cabbage 11a29dd4e0 aindump: fix arg types for opcodes 0x103, 0x105 2020-01-11 18:01:04 -08:00
Nunuhara Cabbage 9f67b40d25 aindump: various improvements
Add index numbers to various output types.
Add local variables to function declarations.
Allow dumping delegates.
2020-01-11 15:24:38 -08:00
Nunuhara Cabbage 70a8b9d136 aindump: correct argument types, all syscalls
Use the correct argument types for all instructions, with the exception
of SH_REF_LOCAL_ASSIGN_STRUCTREF2 which I could find an example of.

List all system calls.
2020-01-11 15:05:45 -08:00
Nunuhara Cabbage 8c226ab535 aindump: support code dump up to ain v12 (Rance X)
v11 ain files have 3 new instructions, and 3 modified instructions. It
looks like they decided to break compatibility with this release by
adding arguments to some instructions.

v12 adds one instruction.
2020-01-10 13:38:19 -08:00
Nunuhara Cabbage 302598ace2 aindump: add decrypt mode
Add -d,--decrypt option to dump decrypted ain file (for reverse
engineering).
2020-01-10 12:28:44 -08:00
Nunuhara Cabbage d764757894 aindump: add "raw" code dumping mode
Add mode which prints all arguments as numbers and does not generate
labels. This is for debugging.
2020-01-10 09:07:26 -08:00
Nunuhara Cabbage 55e44b881a aindump: support dumping code up to Heartful Maman
The argument types for many of the newer instructions are likely
still incorrect.
2020-01-10 08:49:25 -08:00
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