Commit Graph
134 Commits
Author SHA1 Message Date
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
Nunuhara Cabbage c135c4cde7 Implement system.GetFuncStackName() 2019-12-01 22:04:09 -08:00
Nunuhara Cabbage 81455baeb4 Implement more DrawGraph/SACT2 functions
5 functions:

    SACT2.SP_SetDrawMethod
    DrawGraph.CopyStretch
    DrawGraph.CopyStretchAmap
    DrawGraph.CopyReduce
    DrawGraph.CopyReduceAmap

SP_SetDrawMethod is not pixel-perfect to System40.exe, but its pretty
close.

I'm not sure what the difference between the Stretch/Reduce functions is
supposed to be. They seem to do the same thing.

Also, the ugly macros in sdl_draw.c are replaced by higher-order
functions.

With this commit, Sengoku Rance runs up to the menu without exiting due
to unimplemented HLL functions.
2019-12-01 19:50:47 -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 f573614025 Implement SACT2.IntToHankaku + SACT2.IntToZenkaku 2019-12-01 14:08:44 -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 4eb5a256fd Refactor graphics code
Sprites are now rendered directly, rather than being blitted to a master
surface which is then copied to a texture. Every sprite now carries an
SDL_Texture in addition to an SDL_Surface (we need both, since
SDL_Texture doesn't give read-access to the pixel data).

All of the image-manipulation code is now in sdl_draw.c, and the
DrawGraph_* functions are now wrappers. Some games (Daibanchou at least)
use an API other than SACT2/DrawGraph, so these operations should be
generic to avoid duplication.
2019-11-29 23:16:40 -08:00