Commit Graph
40 Commits
Author SHA1 Message Date
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 67b9923ee9 Fix system.GetFuncStackName
This function returns the empty string when the index is invalid.
2022-01-23 14:46:55 -08:00
Nunuhara Cabbage bdf79f99d3 Fix delegates implementation
Delegate page+index is stored on the stack, not part of VM state. It
gets shuffled around via DG_CALLBEGIN.
2022-01-23 14:42:39 -08:00
Nunuhara Cabbage bd0b488a75 Don't call "0" function if it doesn't exist
To support .ain files produced by sys4c which doesn't create the global
alloc function (yet).
2022-01-23 10:33:29 -08:00
kichikuou 08c7b3edd1 Use SDL_OpenURL for system.OpenWeb
It opens a URL in an appropriate way for the platform.
2021-12-25 21:44:59 +09:00
Nunuhara Cabbage 5f221d939f Add -e,--echo-message option
Add option to echo messages to standard output. Messages are prefixed
with "MSG %d:" so that they can be filtered by a script.
2021-12-11 09:57:46 -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
kichikuou 021f74285c Implement SR_REF2 instruction
Used in CConfig@Save of Rance VI.
2021-05-22 17:07:14 +09:00
Nunuhara Cabbage 654e0b4737 Implement various instructions
Implement:
    SH_SASSIGN_STRUCTSREF
    SH_SASSIGN_GLOBALSREF
    SH_STRUCTSREF_NE_STR0
    SH_GLOBALSREF_NE_STR0
    SH_LOC_LT_IMM_OR_LOC_GE_IMM

Also, fix an bug in A_EMPTY and SH_IF_STRUCT_A_NOT_EMPTY.
2021-05-14 22:38:32 -07:00
Nunuhara Cabbage 3249138bf4 Implement SH_REF_LOCAL_ASSIGN_STRUCTREF2
Used in Haruka VS Escalayer
2021-05-13 20:07:16 -07:00
Nunuhara Cabbage ba2accdf58 Implement remaining instructions for Haru Urare
A few of the new instructions which were not used in that game are still
unimplemented.
2021-05-12 16:40:51 -07:00
Nunuhara Cabbage 968179fadb Guard against division by zero
Happens in Haru Urare, apparently this is not an error.
2021-05-10 22:07:23 -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 8ae67056c6 Implement system.CopySaveFile 2021-05-02 17:36:17 -07:00
kichikuou a0d833649a Fix vm_copy() for reference types
This fixes a use-after-free bug in the first battle of Rance VI.
2021-05-01 19:50:09 +09:00
Nunuhara Cabbage 0274052947 Fix memory leak in A_ALLOC
Need to free dst page if already allocated.
2021-04-27 19:15:28 -07:00
Nunuhara Cabbage f0fc236903 Implement system.DeleteSaveFile
Used in Vanish!
2021-04-25 19:25:13 -07:00
Nunuhara Cabbage 152aa8275a Implement various things used in Haruka
* system.ExistFunc
* Math.log + Math.log10
* SystemService mixer functions
2021-04-25 15:40:15 -07:00
Nunuhara Cabbage a10475d185 Implmement system.GetGameName
Used in Beat Blades Haruka.
2021-04-25 10:24:07 -07:00
Nunuhara Cabbage df0f7a590b Implement system.Resume{Read,Write}Comment
Used in お嬢様をいいなりにするゲーム.
2021-04-24 11:00:52 -07:00
kichikuou 843a8cf212 system.GlobalLoad() should not call destructors
Fixes #16.
2021-03-07 10:40:05 +09:00
Nunuhara Cabbage 4adb452490 Convert save filenames to UTF-8
Fixes #6
2020-09-05 08:34:56 -07:00
Nunuhara Cabbage b04b0c3018 Implement system.Reset 2020-08-25 17:47:45 -07:00
Nunuhara Cabbage 76f7e21c95 Improve stack trace
Stack traces now list addresses in addition to function names.
Additionally, debugger stack traces number each frame, and the numbers
can be used together with the PRINT-LOCALS function to print the values
of local variables for any frame on the stack.
2020-08-10 15:51:33 -07:00
Nunuhara Cabbage 1a0a0e0c12 debugger: breakpoints
This is implemented by inserting special opcodes into the game's code.
When the breakpoint handler is finished, it returns the original opcode
so that execute_instruction can continue executing normally.

E.g.

* start xsystem4 with --debug option to drop into debugger immediately
* run (bp "game_main")
* ^d or \exit to close debugger REPL
* ...drop into a debugger REPL again at the game_main function
2020-08-09 12:41:33 -07:00
Nunuhara Cabbage 6a84c8f802 Fix system.GetTime() and SACT2.Timer_Get()
Fixes slow animations in Sengoku Rance (and presumably other games).
2020-08-02 21:04:35 -07:00
Nunuhara Cabbage 58da6dc167 Refactor system4.h
Move xsystem4-specific declarations to xsystem4.h.
2020-07-12 09:17:52 -07:00
Nunuhara Cabbage 2331073e7f Use main() return value as exit code 2020-06-22 17:02:58 -07:00
Nunuhara Cabbage 96dcdea7ce Fix various issues with Windows build 2020-05-18 11:49:48 -07:00
Nunuhara Cabbage 15cdb10ee0 Implement NEW instruction 2020-04-05 13:44:37 -07:00
Nunuhara Cabbage ad7501f962 Implement system.MsgBoxOkCancel 2020-03-06 22:43:42 -08:00
Nunuhara Cabbage 7f5e155f3e Implement system.OpenWeb 2020-03-05 19:05:10 -08:00
Nunuhara Cabbage 3fa214a22a Implement system.Sleep 2020-01-16 06:04:00 -08:00
Nunuhara Cabbage 32bee0c242 aindump: print array types properly
Print the new v11+ array types properly. Also, print the array rank for
old array types.

The code for reading v11+ ain data is simplified a lot here as well.
2020-01-14 20:43:10 -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 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