Compare commits

...
Author SHA1 Message Date
kichikuou 3d70d00bce Add unit test for gameresource.c 2020-07-11 19:12:45 +09:00
kichikuou f2fbf54c32 Move registerGameFiles to xsystem35.c 2020-07-11 18:34:27 +09:00
kichikuou b4d2c0832e Clean up gameresource.c 2020-07-11 18:34:24 +09:00
kichikuou d777b18b55 Game Resource: Allow file names containing spaces 2020-07-11 18:23:39 +09:00
kichikuou 7b3efd9aaa Move *.gr reader code to gameresource.c 2020-07-11 18:22:05 +09:00
kichikuou 90eb139994 Merge pull request #17 from nunuhara/missing_font_fix
Fix segfault when non-existent font specified
2020-07-11 16:15:13 +09:00
Nunuhara Cabbage aa87e3e8c0 Fix segfault when non-existent font specified 2020-07-10 23:43:46 -07:00
kichikuou 1cd949f597 CMake: Fix X11 + SDL_mixer build
Stop using SDL2_FOUND to determine if SDL2 should be used or not,
because it may be defined as a side effect of
pkg_check_modules(SDL2_mixer).
2020-06-27 15:05:56 +09:00
kichikuou 426cdaa836 Fix compatibility issues around maximum index of array variables
The second argument of DC command specifies the maximum index of the new
array. That means, `DC _,n,_:` allocates an array of size n+1 (a[0] to
a[n]).

This patch makes sure various D commands work with a[n], and a[n] is
correctly saved and loaded.

Now loadSysVar() does not shrink array variables using the data count in
the save file, so that files saved by old xsystem35 binary can be safely
loaded. This also matches the behavior of System3.9.
2020-06-27 13:16:22 +09:00
kichikuou 8db5a9cd65 Implement text decoration type 4 and 10 2020-06-21 11:10:19 +09:00
kichikuou 47f82e87c5 Add guards against incomplete SJIS bytes 2020-06-21 09:49:13 +09:00
kichikuou 86470e543a Rework string variables
- strVar is now allocated as a vector of indefinite length buffers
  rather than a single contiguous buffer.
- Strings can be any length, but truncated to (strvar_len * 2) bytes
  when saved to a file, for backward compatibility.
- Now string commands treat 1-byte characters in the same way as System
  3.9. This potentially fixes bugs in English translated games.
2020-06-20 22:29:22 +09:00
kichikuou a23ce19433 Add tests for string variables (M commands)
xsystem35 does not pass yet.
2020-06-20 13:00:32 +09:00
kichikuou 1cf197513c Use const strings in message related functions 2020-06-20 10:53:38 +09:00
kichikuou 64c3c28336 CI: Run SDL2 and X11 builds on Linux 2020-06-20 10:52:35 +09:00
kichikuou 7309ed012f Make DspDeviceSync no-op in SDL graphics 2020-06-18 21:49:51 +09:00
kichikuou 515a92544b getCaliValue: Recover from out-of-bounds index access
Before this, array access caused stack underflow if the index was out of
range. After this, such index access will be evaluated to zero.
2020-06-14 22:43:17 +09:00
kichikuou 725b0ee6ab Prevent buffer overrun by DF command 2020-06-14 22:09:14 +09:00
kichikuou e17b447e73 Cleanup variable lookup code
No behavior changes.
2020-06-14 21:54:11 +09:00
kichikuou 6dbd31cdbc Add tests for array access 2020-06-14 21:48:52 +09:00
kichikuou a217df39b1 Fix compiler warnings on Windows
On Windows, jpeglib.h includes windows.h which defines several macros
that conflict with ours.
2020-06-14 14:23:40 +09:00
kichikuou 80266d6454 Support JPEG image format
JPEG images are not used in AliceSoft games, but supported since System3.6
version 3.23 and used in some third-party games (e.g. Graymerca).
2020-06-14 14:16:19 +09:00
kichikuou 2e17188f2b Fix DI command and add tests 2020-06-13 15:46:45 +09:00
kichikuou 37f4d847e5 Fix Windows build 2020-06-07 21:29:53 +09:00
kichikuou 43c6688ce7 CI updates
- Add Windows build
- Run Debug and Release builds on Linux
- Run CI against pull requests
2020-06-07 15:16:39 +09:00
kichikuou 09e89e794d Android: Version 0.2.1 2020-06-07 14:31:31 +09:00
kichikuou 3fd7a58544 Android: Use filtered scaling
This improves text readability, especially for the Mincho font.
2020-06-07 12:55:16 +09:00
kichikuou f0ccdcf40a Android: Use arhive filename as alternate launcher item name
The title.txt file is written when the MT command is used, however some
games (Daiakuji, AmbivalenZ, Ikenai Katsumi sensei) does not use the MT
command. As a result, these titles did not appear in the launcher.

This makes the launcher use the name of the ZIP archive when the game
was installed as the alternate item name if the MT command was not used.
2020-06-07 12:23:19 +09:00
kichikuou 1a6b7b33b9 Android: Compile SDL_mixer with ogg support
This enables voice playback in Escalayer.
2020-06-06 23:00:39 +09:00
kichikuou 7240971beb Fix SACT.MessageIsEmpty
This fixes a bug where message wasn't flushed before changing text
attributes.
2020-06-06 18:27:20 +09:00
71 changed files with 1297 additions and 507 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
name: Android Build
on: [push]
on: [push, pull_request]
jobs:
build:
+1 -1
View File
@@ -1,5 +1,5 @@
name: Emscripten Build
on: [push]
on: [push, pull_request]
env:
emscripten-version: 1.39.16
+28 -6
View File
@@ -1,10 +1,14 @@
name: Linux Build
on: [push]
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
build-type: ["Debug", "Release"]
name: Linux ${{ matrix.build-type }}
steps:
- uses: actions/checkout@v2
@@ -15,11 +19,29 @@ jobs:
- name: Build
run: |
mkdir -p out/debug
cd out/debug
cmake -DCMAKE_BUILD_TYPE=Debug ../../
mkdir -p out/${{ matrix.build-type }}
cd out/${{ matrix.build-type }}
cmake -DENABLE_X11=NO -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} ../../
make
- name: Test
run: ctest
working-directory: out/debug
run: ctest --output-on-failure
working-directory: out/${{ matrix.build-type }}
build-x11:
runs-on: ubuntu-latest
name: Linux X11
steps:
- uses: actions/checkout@v2
- name: Build
run: |
mkdir -p out
cd out
cmake ../
make
- name: Test
run: ctest --output-on-failure
working-directory: out
+48
View File
@@ -0,0 +1,48 @@
name: Windows Build
on: [push, pull_request]
jobs:
build:
runs-on: windows-2019
strategy:
matrix:
mingw: ["MINGW32", "MINGW64"]
include:
- mingw: "MINGW32"
package: "mingw-w64-i686"
- mingw: "MINGW64"
package: "mingw-w64-x86_64"
defaults:
run:
shell: bash.exe --login -eo pipefail "{0}"
env:
MSYSTEM: ${{ matrix.mingw }}
CHERE_INVOKING: 1
name: MSYS2 ${{ matrix.mingw }}
steps:
- name: Set up shell
run: echo ::add-path::C:\msys64\usr\bin\
shell: pwsh
- name: Print system version
run: |
uname
echo PATH: $PATH
- name: Install Deps
run: pacman -S --noconfirm ${{ matrix.package }}-SDL2 ${{ matrix.package }}-SDL2_ttf ${{ matrix.package }}-SDL2_mixer ${{ matrix.package }}-libjpeg-turbo
- name: Checkout
uses: actions/checkout@v2
- name: Build
run: |
mkdir -p out/debug
cd out/debug
cmake -G"MSYS Makefiles" -DCMAKE_BUILD_TYPE=Debug ../../
make
- name: Test
run: ctest --output-on-failure
working-directory: out/debug
+7 -5
View File
@@ -71,13 +71,15 @@ else()
optional_find_package(Freetype)
include(FindPkgConfig)
if (NOT X11_FOUND)
optional_pkg_check_modules(SDL2 IMPORTED_TARGET sdl2)
endif()
optional_pkg_check_modules(SDL2 IMPORTED_TARGET sdl2)
optional_pkg_check_modules(SDL2MIXER IMPORTED_TARGET SDL2_mixer)
optional_pkg_check_modules(SDL2TTF IMPORTED_TARGET SDL2_ttf)
include(FindJPEG)
if (JPEG_FOUND)
set(HAVE_JPEG 1)
endif()
set(DEFAULT_FONT_PATH ${CMAKE_INSTALL_PREFIX}/share/xsystem35/fonts/)
endif()
@@ -197,7 +199,7 @@ endif()
if (EMSCRIPTEN OR ANDROID)
set(SRC_JOYSTICK joystick_dmy.c)
elseif (SDL2_FOUND)
elseif (ENABLE_SDL)
set(SRC_JOYSTICK joystick_sdl.c)
set(SUMMARY_JOYSTICK "SDL")
set(HAVE_SDLJOY 1)
+2 -2
View File
@@ -20,7 +20,7 @@ cmake の実行でエラーになる場合は必要なライブラリをイン
[Homebrew](https://brew.sh/index_ja) が必要です。
$ brew install cmake pkg-config sdl2 sdl2_mixer freetype
$ brew install cmake pkg-config sdl2 sdl2_mixer freetype libjpeg
$ mkdir -p out/debug
$ cd out/debug
$ cmake -DCMAKE_BUILD_TYPE=Debug ../../
@@ -30,7 +30,7 @@ cmake の実行でエラーになる場合は必要なライブラリをイン
[MSYS2](https://www.msys2.org) が必要です。
$ pacman -S cmake mingw-w64-x86_64-cmake mingw-w64-x86_64-SDL2 mingw-w64-x86_64-SDL2_ttf mingw-w64-x86_64-SDL2_mixer
$ pacman -S cmake mingw-w64-x86_64-cmake mingw-w64-x86_64-SDL2 mingw-w64-x86_64-SDL2_ttf mingw-w64-x86_64-SDL2_mixer mingw-w64-x86_64-libjpeg-turbo
$ mkdir -p out/debug
$ cd out/debug
$ cmake -G"MSYS Makefiles" -DCMAKE_BUILD_TYPE=Debug ../../
+2 -2
View File
@@ -16,8 +16,8 @@ android {
}
minSdkVersion 19
targetSdkVersion 26
versionCode 3
versionName "0.2.0"
versionCode 4
versionName "0.2.1"
externalNativeBuild {
cmake {
arguments "-DANDROID_APP_PLATFORM=android-16", "-DANDROID_STL=c++_static"
+1
View File
@@ -40,6 +40,7 @@ endif()
FetchContent_GetProperties(SDL_mixer)
if(NOT sdl_mixer_POPULATED)
FetchContent_Populate(SDL_mixer)
SET(SUPPORT_OGG ON CACHE BOOL "Enable OGG support in SDL_mixer" FORCE)
add_subdirectory(${sdl_mixer_SOURCE_DIR} ${sdl_mixer_BINARY_DIR})
# Workaround for CMakeLists.txt bugs of SDL_mixer.
# TODO: Fix these in upstream
@@ -29,6 +29,7 @@ import java.io.IOException
class GameActivity : SDLActivity() {
companion object {
const val EXTRA_GAME_ROOT = "GAME_ROOT"
const val EXTRA_ARCHIVE_NAME = "ARCHIVE_NAME"
}
private lateinit var gameRoot: File
@@ -63,9 +64,12 @@ class GameActivity : SDLActivity() {
override fun setTitle(title: CharSequence?) {
super.setTitle(title)
val str = title?.toString()?.substringAfter(':', "")
if (str.isNullOrEmpty())
return
var str = title?.toString()?.substringAfter(':', "")
if (str.isNullOrEmpty()) {
str = intent.getStringExtra(EXTRA_ARCHIVE_NAME)
if (str == null)
return
}
File(gameRoot, Launcher.TITLE_FILE).writeText(str)
Launcher.updateGameList()
}
@@ -35,7 +35,7 @@ private var gLauncher: Launcher? = null
interface LauncherObserver {
fun onGameListChange()
fun onInstallProgress(path: String)
fun onInstallSuccess(path: File)
fun onInstallSuccess(path: File, archiveName: String?)
fun onInstallFailure(msgId: Int)
}
@@ -73,7 +73,7 @@ class Launcher private constructor(private val rootDir: File) {
updateGameList()
}
fun install(input: InputStream) {
fun install(input: InputStream, archiveName: String?) {
val dir = createDirForGame()
@SuppressLint("HandlerLeak")
val handler = object : Handler() {
@@ -84,7 +84,7 @@ class Launcher private constructor(private val rootDir: File) {
}
SUCCESS -> {
isInstalling = false
observer?.onInstallSuccess(msg.obj as File)
observer?.onInstallSuccess(msg.obj as File, archiveName)
}
FAILURE -> {
isInstalling = false
@@ -19,7 +19,9 @@ package io.github.kichikuou.xsystem35
import android.app.*
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.provider.OpenableColumns
import android.util.Log
import android.view.Menu
import android.view.MenuItem
@@ -60,7 +62,7 @@ class LauncherActivity : ListActivity(), AdapterView.OnItemLongClickListener, La
override fun onListItemClick(l: ListView?, v: View?, position: Int, id: Long) {
super.onListItemClick(l, v, position, id)
if (position < launcher.games.size) {
startGame(launcher.games[position].path)
startGame(launcher.games[position].path, null)
} else {
val i = Intent(Intent.ACTION_GET_CONTENT)
i.type = CONTENT_TYPE_ZIP
@@ -112,7 +114,7 @@ class LauncherActivity : ListActivity(), AdapterView.OnItemLongClickListener, La
INSTALL_REQUEST -> {
val input = contentResolver.openInputStream(uri) ?: return
showProgressDialog()
launcher.install(input)
launcher.install(input, getArchiveName(uri))
}
SAVEDATA_EXPORT_REQUEST -> try {
launcher.exportSaveData(contentResolver.openOutputStream(uri)!!)
@@ -144,9 +146,9 @@ class LauncherActivity : ListActivity(), AdapterView.OnItemLongClickListener, La
progressDialog?.setProgress(getString(R.string.install_progress, path))
}
override fun onInstallSuccess(path: File) {
override fun onInstallSuccess(path: File, archiveName: String?) {
dismissProgressDialog()
startGame(path)
startGame(path, archiveName)
}
override fun onInstallFailure(msgId: Int) {
@@ -154,10 +156,11 @@ class LauncherActivity : ListActivity(), AdapterView.OnItemLongClickListener, La
errorDialog(msgId)
}
private fun startGame(path: File) {
private fun startGame(path: File, archiveName: String?) {
val i = Intent()
i.setClass(applicationContext, GameActivity::class.java)
i.putExtra(GameActivity.EXTRA_GAME_ROOT, path.path)
i.putExtra(GameActivity.EXTRA_ARCHIVE_NAME, archiveName)
startActivity(i)
}
@@ -181,6 +184,17 @@ class LauncherActivity : ListActivity(), AdapterView.OnItemLongClickListener, La
.setPositiveButton(R.string.ok) {_, _ -> }
.show()
}
private fun getArchiveName(uri: Uri): String? {
val cursor = contentResolver.query(uri, null, null, null, null, null)
cursor?.use {
if (it.moveToFirst()) {
val fname = it.getString(it.getColumnIndex(OpenableColumns.DISPLAY_NAME))
return if (fname.endsWith(".zip", true)) fname.dropLast(4) else fname
}
}
return null
}
}
@Suppress("DEPRECATION") // for ProgressDialog
+1
View File
@@ -33,6 +33,7 @@
#cmakedefine QUIET_MIDI @QUIET_MIDI@
#cmakedefine HAVE_GETLOGIN @HAVE_GETLOGIN@
#cmakedefine HAVE_JPEG @HAVE_JPEG@
#cmakedefine HAVE_MMAP @HAVE_MMAP@
#cmakedefine HAVE_SDLJOY @HAVE_SDLJOY@
#cmakedefine HAVE_SIGACTION @HAVE_SIGACTION@
+1 -1
View File
@@ -27,7 +27,7 @@
Midi : MIDIデータ
Data : その他データ
Save : セーブデータ
Resouce : リソースファイル(マウスカーソル形状)
Resource : リソースファイル(マウスカーソル形状)
Ain : DLL とその関数の情報のかかれた System39.ain
BGM : BGMデータ(エスカレイヤー以降のBGMデータファイル)
WAI : PCMデータの追加情報 (mixer channel 情報等)
+1 -3
View File
@@ -81,9 +81,7 @@ if (SDL2MIXER_FOUND)
endif()
endif()
include(FindJPEG)
if (JPEG_FOUND)
target_compile_definitions(modules PRIVATE HAVE_JPEG)
if (HAVE_JPEG)
target_sources(modules PRIVATE
NightDemonDemo/ndd.c
NightDemonDemo/jpeg2surface.c
+1 -1
View File
@@ -179,7 +179,7 @@ void ntmsg_newline() {
ntmsg_add(buf);
}
void ntmsg_add(char *msg) {
void ntmsg_add(const char *msg) {
int len;
SACT_DEBUG("len = %d\n", strlen(msg));
+1 -1
View File
@@ -5,7 +5,7 @@ extern void ntmsg_init();
extern void ntmsg_set_frame(int type);
extern void ntmsg_set_place(int type);
extern void ntmsg_newline();
extern void ntmsg_add(char *msg);
extern void ntmsg_add(const char *msg);
extern int ntmsg_ana(void);
extern int ntmsg_update(sprite_t *sp, MyRectangle *r);
+5 -2
View File
@@ -21,10 +21,13 @@
*/
/* $Id: jpeg2surface.c,v 1.2 2003/11/09 15:06:12 chikama Exp $ */
#include "config.h"
#include <stdio.h>
#include <jpeglib.h>
#undef ERROR
#undef max
#undef min
#include "config.h"
#include "portab.h"
#include "ags.h"
-1
View File
@@ -63,7 +63,6 @@ typedef struct {
// SACTEFAM を使ったマスク
typedef struct {
int fd; // SACTEFAM.KLD のファイルディスクプリタ
char *mapadr; // mmap された最初のアドレス
off_t size; // mmap した大きさ
int datanum; // SACTEFAM.KLD 中のマスクファイルの数
+19 -2
View File
@@ -28,10 +28,12 @@
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#ifdef HAVE_MMAP
#include <sys/mman.h>
#endif
#include "portab.h"
#include "system.h"
@@ -76,16 +78,31 @@ int smask_init(char *path) {
return NG;
}
#ifdef HAVE_MMAP
if (MAP_FAILED == (adr = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, fd, 0))) {
WARNING("mmap: %s\n", strerror(errno));
close(fd);
return NG;
}
#else
adr = malloc(sbuf.st_size);
size_t bytes = 0;
while (bytes < sbuf.st_size) {
ssize_t ret = read(fd, adr + bytes, sbuf.st_size - bytes);
if (ret <= 0) {
WARNING("read: %s\n", strerror(errno));
close(fd);
free(adr);
return NG;
}
bytes += ret;
}
#endif
close(fd);
am = &sact.am;
am->mapadr = adr;
am->size = sbuf.st_size;
am->fd = fd;
am->datanum = LittleEndian_getDW(adr, 0);
am->no = malloc(sizeof(int) * am->datanum);
+1 -1
View File
@@ -83,7 +83,7 @@ extern void sp_draw_dmap(void* data, void* userdata);
// in sprite_msg.c
extern void smsg_add(char *msg);
extern void smsg_add(const char *msg);
extern void smsg_newline(int wNum, int size);
extern void smsg_out(int wNum, int wSize, int wColorR, int wColorG, int wColorB, int wFont, int wSpeed, int wLineSpace, int wAlign, int wRSize, int wRFont, int wRLineSpace, int *wLength);
extern void smsg_clear(int wNum);
+3 -3
View File
@@ -188,7 +188,7 @@ static int setupmark(int wNum1, int wNum2, struct markinfo *minfo) {
@param msg: 追加する文字列
*/
void smsg_add(char *msg) {
void smsg_add(const char *msg) {
int len;
if (msg[0] == '\0') return;
@@ -392,10 +392,10 @@ void smsg_clear(int wNum) {
/*
出力中の文字列があるかチェック
@return: なし(0) , あり(1)
@return: なし(1) , あり(0)
*/
int smsg_is_empty() {
return (sact.msgbuf[0] != '\0');
return (sact.msgbuf[0] == '\0');
}
/*
+3 -3
View File
@@ -45,8 +45,8 @@ static void ExchangeString(void) {
int target = getCaliValue();
int pat = getCaliValue();
int patr = getCaliValue();
char *start = v_str(target -1);
char *next;
const char *start = v_str(target -1);
const char *next;
char dst[STRVAR_LEN] = "";
DEBUG_COMMAND("ShString.ExchangeString: %d,%d,%d:\n", target, pat, patr);
@@ -144,7 +144,7 @@ static void SetStringNum16(void) {
*/
int st = getCaliValue();
int *var = getCaliVariable();
char *str = v_str(st -1);
const char *str = v_str(st -1);
char _dst[100];
char *dst = _dst;
+28 -5
View File
@@ -29,10 +29,12 @@
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#ifdef HAVE_MMAP
#include <sys/mman.h>
#endif
#include "portab.h"
#include "system.h"
@@ -56,23 +58,41 @@ alk_t *alk_new(char *path) {
return NULL;
}
#ifdef HAVE_MMAP
if (MAP_FAILED == (adr = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, fd, 0))) {
WARNING("mmap: %s\n", strerror(errno));
close(fd);
return NULL;
}
#else
adr = malloc(sbuf.st_size);
size_t bytes = 0;
while (bytes < sbuf.st_size) {
ssize_t ret = read(fd, adr + bytes, sbuf.st_size - bytes);
if (ret <= 0) {
WARNING("read: %s\n", strerror(errno));
close(fd);
free(adr);
return NULL;
}
bytes += ret;
}
#endif
close(fd);
if (0 != strncmp(adr, "ALK0", 4)) {
WARNING("mmap: %s\n", strerror(errno));
WARNING("%s: not an ALK file\n", path);
#ifdef HAVE_MMAP
munmap(adr, sbuf.st_size);
close(fd);
#else
free(adr);
#endif
return NULL;
}
alk = calloc(1, sizeof(alk_t));
alk->mapadr = adr;
alk->size = sbuf.st_size;
alk->fd = fd;
alk->datanum = LittleEndian_getDW(adr, 4);
alk->offset = malloc(sizeof(int) * alk->datanum);
@@ -87,8 +107,11 @@ alk_t *alk_new(char *path) {
int alk_free(alk_t *alk) {
if (alk == NULL) return OK;
#ifdef HAVE_MMAP
munmap(alk->mapadr, alk->size);
close(alk->fd);
#else
free(alk->mapadr);
#endif
free(alk->offset);
free(alk);
-1
View File
@@ -38,7 +38,6 @@
*/
typedef struct {
int fd; /* .alk ファイルの file discpriter */
char *mapadr; /* mmap したファイルの先頭アドレス */
off_t size; /* mmap したバイト数(ファイルサイズ) */
int datanum; /* .alk ファイル中のファイル数 */
+10 -1
View File
@@ -11,6 +11,7 @@ target_sources(xsystem35 PRIVATE
dri.c
ald_manager.c
cache.c
gameresource.c
${SRC_AUDIO}
${SRC_CDROM}
${SRC_MIDI}
@@ -28,6 +29,10 @@ target_sources(xsystem35 PRIVATE
# CG
target_sources(xsystem35 PRIVATE
pms.c vsp.c bmp.c qnt.c)
if (HAVE_JPEG)
target_sources(xsystem35 PRIVATE jpeg.c)
target_link_libraries(xsystem35 PRIVATE JPEG::JPEG)
endif()
# Music
target_sources(xsystem35 PRIVATE
@@ -89,7 +94,7 @@ else() # non-emscripten, non-android
if (FREETYPE_FOUND)
target_link_libraries(xsystem35 PRIVATE Freetype::Freetype)
endif()
if (SDL2_FOUND)
if (ENABLE_SDL)
target_link_libraries(xsystem35 PRIVATE PkgConfig::SDL2)
endif()
if (SDL2MIXER_FOUND)
@@ -100,6 +105,10 @@ else() # non-emscripten, non-android
endif()
install(TARGETS xsystem35 RUNTIME DESTINATION bin)
add_executable(src_tests src_tests.c gameresource_test.c gameresource.c)
add_test(NAME src_tests COMMAND src_tests)
configure_file(testdata/test.gr ${CMAKE_CURRENT_BINARY_DIR}/testdata/test.gr COPYONLY)
endif()
# FIXME: set up dependency for xsystem35 on this
+2 -2
View File
@@ -184,7 +184,7 @@ void ags_setViewArea(int x, int y, int width, int height) {
SetWindowSize(x, y, width, height);
}
void ags_setWindowTitle(char *src) {
void ags_setWindowTitle(const char *src) {
#define TITLEHEAD "XSystem35 Version "VERSION":"
BYTE *dst, *d;
@@ -396,7 +396,7 @@ void ags_delRegion(void *region) {
DelRegion(region);
}
int ags_drawString(int x, int y, char *src, int col) {
int ags_drawString(int x, int y, const char *src, int col) {
int w;
if (!check_param_xy(&x, &y)) return 0;
+15 -15
View File
@@ -33,19 +33,19 @@
/* マウスカーソルの種類 */
#define IDC_ARROW 1
#define IDC_CROSS 2
#define IDC_IBEAM 3
#define IDC_ICON 4
#define IDC_NO 5
#define IDC_SIZE 6
#define IDC_SIZEALL 7
#define IDC_SIZENESW 8
#define IDC_SIZENS 9
#define IDC_SIZENWSE 10
#define IDC_SIZEWE 11
#define IDC_UPARROW 12
#define IDC_WAIT 13
#define CURSOR_ARROW 1
#define CURSOR_CROSS 2
#define CURSOR_IBEAM 3
#define CURSOR_ICON 4
#define CURSOR_NO 5
#define CURSOR_SIZE 6
#define CURSOR_SIZEALL 7
#define CURSOR_SIZENESW 8
#define CURSOR_SIZENS 9
#define CURSOR_SIZENWSE 10
#define CURSOR_SIZEWE 11
#define CURSOR_UPARROW 12
#define CURSOR_WAIT 13
/* RGB <-> alpha plane copy type */
typedef enum {
@@ -151,7 +151,7 @@ extern void ags_remove();
/* ウィンド関係 */
extern void ags_setWorldSize(int width, int height, int depth);
extern void ags_setViewArea(int x, int y, int width, int height);
extern void ags_setWindowTitle(char *str);
extern void ags_setWindowTitle(const char *str);
extern void ags_getDIBInfo(DispInfo *info);
extern void ags_getWindowInfo(DispInfo *info);
extern void ags_getViewAreaInfo(DispInfo *info);
@@ -194,7 +194,7 @@ extern void ags_putRegion(void *region, int x, int y);
extern void ags_copyRegion(void *region, int sx, int sy, int w,int h,int dx,int dy);
extern void ags_delRegion(void *region);
extern int ags_drawString(int x, int y, char *src, int col);
extern int ags_drawString(int x, int y, const char *src, int col);
extern void ags_drawCg8bit(cgdata *cg, int x, int y);
extern void ags_drawCg16bit(cgdata *cg, int x, int y);
+19 -28
View File
@@ -64,52 +64,44 @@ static int *fixOffset(int base, int offset2) {
int page, offset;
int *index;
preVarPage = (sysVarAttribute + base) -> page;
preVarPage = sysVarAttribute[base].page;
preVarNo = base;
if ((sysVarAttribute + base) -> page == 0) {
if (sysVarAttribute[base].page == 0) {
if (offset2 == -1) {
#ifdef DEBUG_CHECKALING
if (base >= SYSVAR_MAX) {
WARNING("sysVar[no] ArrayIndexOutofException (%d, %d)\n", base, offset2);
WARNING("%03d:%05x: ArrayIndexOutOfBounds (%d, %d)\n", sl_getPage(), sl_getIndex(), base, offset2);
return NULL;
}
#endif
preVarIndex = base;
return sysVar + base;
} else {
#ifdef DEBUG_CHECKALING
if ((base + offset2) >= SYSVAR_MAX) {
WARNING("sysVar[no] ArrayIndexOutofException (%d, %d)\n", base, offset2);
WARNING("%03d:%05x: ArrayIndexOutOfBounds (%d, %d)\n", sl_getPage(), sl_getIndex(), base, offset2);
return NULL;
}
#endif
preVarIndex = base + offset2;
return sysVar + base + offset2;
}
} else {
if (offset2 == -1) {
index = (sysVarAttribute + base) -> pointvar;
page = (sysVarAttribute + base) -> page;
offset = (sysVarAttribute + base) -> offset;
#ifdef DEBUG_CHECKALING
if ((*index) + offset > (arrayVarBuffer + page - 1)->max) {
WARNING("sysVar[no] ArrayIndexOutofException (%d, %d, %d, %d, %d)\n", base, offset2, *index, page, offset);
index = sysVarAttribute[base].pointvar;
page = sysVarAttribute[base].page;
offset = sysVarAttribute[base].offset;
if (*index + offset >= arrayVarBuffer[page - 1].size) {
WARNING("%03d:%05x: ArrayIndexOutOfBounds (%d, %d, %d, %d, %d)\n", sl_getPage(), sl_getIndex(), base, offset2, *index, page, offset);
return NULL;
}
#endif
preVarIndex = offset + (*index);
return ((arrayVarBuffer + page - 1) -> value) + offset + (*index);
preVarIndex = offset + *index;
return arrayVarBuffer[page - 1].value + offset + *index;
} else {
page = (sysVarAttribute + base) -> page;
offset = (sysVarAttribute + base) -> offset;
#ifdef DEBUG_CHECKALING
if (offset + offset2 > (arrayVarBuffer + page - 1)->max) {
WARNING("sysVar[no] ArrayIndexOutofException (%d, %d, %d, %d)\n", base, offset2, page, offset);
page = sysVarAttribute[base].page;
offset = sysVarAttribute[base].offset;
if (offset + offset2 >= arrayVarBuffer[page - 1].size) {
WARNING("%03d:%05x: ArrayIndexOutOfBounds (%d, %d, %d, %d)\n", sl_getPage(), sl_getIndex(), base, offset2, page, offset);
return NULL;
}
#endif
preVarIndex = offset + offset2;
return ((arrayVarBuffer + page - 1) -> value) + offset + offset2;
return arrayVarBuffer[page - 1].value + offset + offset2;
}
}
}
@@ -203,8 +195,7 @@ int getCaliValue() {
}
l_var:
t = getVar(c0);
if (t == NULL) continue;
*cali = *t; cali++;
*cali++ = t ? *t : 0;
} else {
switch(c0) {
case 0x7e: /* != */
@@ -304,12 +295,12 @@ int getCaliValue() {
}
}
c0 = *--cali;
#ifdef DEBUG_CHECKALING
if (cali != bufc) {
WARNING("Something is wrong @ %03d:%05x\n", sl_getPage(), sl_getIndex());
cali = bufc;
return 0;
}
#endif
return c0;
}
+22 -1
View File
@@ -33,6 +33,9 @@
#include "pms.h"
#include "bmp.h"
#include "qnt.h"
#ifdef HAVE_JPEG
#include "jpeg.h"
#endif
#include "ald_manager.h"
#include "savedata.h"
#include "cache.h"
@@ -85,6 +88,10 @@ static CG_TYPE check_cgformat(BYTE *data) {
return ALCG_BMP8;
} else if (vsp_checkfmt(data)) {
return ALCG_VSP;
#ifdef HAVE_JPEG
} else if (jpeg_checkfmt(data) && nact->sys_world_depth >= 15) {
return ALCG_JPEG;
#endif
}
WARNING("Unknown Cg Type\n");
return ALCG_UNKNOWN;
@@ -182,6 +189,7 @@ static void display_cg(cgdata *cg, int x, int y) {
ags_drawCg8bit(cg, x, y); break;
case ALCG_PMS16:
case ALCG_BMP24:
case ALCG_JPEG:
ags_drawCg16bit(cg, x, y); break;
default:
break;
@@ -243,6 +251,12 @@ static cgdata *loader(int no) {
cg = qnt_extract(dfile->data);
size = (cg->width * cg->height) * 3;
break;
#ifdef HAVE_JPEG
case ALCG_JPEG:
cg = jpeg_extract(dfile->data, dfile->size);
size = (cg->width * cg->height) * sizeof(WORD);
break;
#endif
default:
break;
}
@@ -395,6 +409,7 @@ void cg_load(int no, int flg) {
break;
case ALCG_PMS16:
case ALCG_BMP24:
case ALCG_JPEG:
if (GCMD_EXTRACTCG(cg_fflg)) {
/* set display offset */
p = set_display_loc(cg);
@@ -463,11 +478,12 @@ void cg_load_with_alpha(int cgno, int shadowno) {
*/
int cg_load_with_filename(char *name, int x, int y) {
int status, type;
long filesize;
BYTE *data;
cgdata *cg = NULL;
MyPoint p;
data = load_cg_with_file(name, &status);
data = load_cg_with_file(name, &status, &filesize);
if (data == NULL) return status;
cg_set_display_location(x, y, OFFSET_ABSOLUTE_GC);
@@ -480,6 +496,11 @@ int cg_load_with_filename(char *name, int x, int y) {
case ALCG_BMP24:
cg = bmp16m_extract(data);
break;
#ifdef HAVE_JPEG
case ALCG_JPEG:
cg = jpeg_extract(data, filesize);
break;
#endif
default:
return status;
}
+2 -1
View File
@@ -37,7 +37,8 @@ typedef enum {
ALCG_PMS16 = 4,
ALCG_BMP8 = 5,
ALCG_BMP24 = 6,
ALCG_QNT = 7
ALCG_QNT = 7,
ALCG_JPEG = 8,
} CG_TYPE;
/*
+3 -5
View File
@@ -749,14 +749,12 @@ void commands2F44() {
char s[256];
if (fig) {
char *ss="%%%dd";
char sss[256];
sprintf(sss, ss, fig);
sprintf(s, sss, num2);
sprintf(s, "%*d", fig, num2);
v_strcpy(num1 - 1, s + strlen(s) - fig);
} else {
sprintf(s, "%d", num2);
v_strcpy(num1 - 1, s);
}
v_strcpy(num1 - 1, s);
DEBUG_COMMAND("MHH %d, %d, %d:\n", num1, fig, num2);
}
+17 -7
View File
@@ -28,26 +28,26 @@
void commandDC() {
int page = getCaliValue();
int size = getCaliValue();
int maxindex = getCaliValue();
int save = getCaliValue();
boolean bool;
bool = v_allocateArrayBuffer(page , size, save == 0 ? false : true);
bool = v_allocateArrayBuffer(page, maxindex + 1, save == 0 ? false : true);
if(!bool) {
WARNING("commandDC(): Array allocate failed\n");
}
DEBUG_COMMAND("DC %d,%d,%d:\n", page, size, save);
DEBUG_COMMAND("DC %d,%d,%d:\n", page, maxindex, save);
}
void commandDI() {
int page = getCaliValue();
int *var_use = getCaliVariable();
int *var_size = getCaliVariable();
int *var_save = getCaliVariable();
*var_size = v_releaseArrayVar(page);
*var_save = v_getArrayBufferCnt(page) == true ? 1 : 0;
*var_use = v_getArrayBufferStatus(page);
*var_size = arrayVarBuffer[page - 1].size & 0xffff;
DEBUG_COMMAND("DI %d,%p,%p:\n", page, var_size, var_save);
DEBUG_COMMAND("DI %d,%p,%p:\n", page, var_use, var_size);
}
void commandDS() {
@@ -76,11 +76,21 @@ void commandDR() {
void commandDF() {
int *data_var = getCaliVariable();
int varno = preVarNo;
int cnt = getCaliValue();
int data = getCaliValue();
DEBUG_COMMAND("DF %p,%d,%d:\n", data_var, cnt, data);
const arrayVarStruct* array = &sysVarAttribute[varno];
if (array->page) {
int maxlen = arrayVarBuffer[array->page - 1].size - array->offset - *array->pointvar;
if (cnt > maxlen) {
WARNING("%03d:%05x: count exceeds array boundary (%d > %d)\n", sl_getPage(), sl_getIndex(), cnt, maxlen);
cnt = maxlen;
}
}
while (cnt--) {
*data_var = data; data_var++;
}
+18 -24
View File
@@ -135,8 +135,14 @@ void commandMA() {
/* num1 の文字列の後ろに num2 をつなげる */
int num1 = getCaliValue();
int num2 = getCaliValue();
v_strcat(num1 - 1, v_str(num2 - 1));
if (num1 == num2) {
char *buf = strdup(v_str(num2 - 1));
v_strcat(num1 - 1, buf);
free(buf);
} else {
v_strcat(num1 - 1, v_str(num2 - 1));
}
DEBUG_COMMAND("MA %d,%d:\n",num1,num2);
}
@@ -176,7 +182,8 @@ void commandMM() {
int num1 = getCaliValue();
int num2 = getCaliValue();
v_strcpy(num1 - 1, v_str(num2 - 1));
if (num1 != num2)
v_strcpy(num1 - 1, v_str(num2 - 1));
DEBUG_COMMAND("MM %d,%d:\n",num1, num2);
}
@@ -236,8 +243,7 @@ void commandMD() {
int src_str_no = getCaliValue();
int len = getCaliValue();
strncpy(v_str(dst_str_no - 1), v_str(src_str_no - 1), len * 2);
*(v_str(dst_str_no - 1) + len*2) = '\0';
v_strncpy(dst_str_no - 1, 0, src_str_no - 1, 0, len);
DEBUG_COMMAND("MD %d,%d,%d:\n",dst_str_no, src_str_no, len);
}
@@ -250,8 +256,7 @@ void commandME() {
int src_pos = getCaliValue();
int len = getCaliValue();
strncpy(v_str(dst_str_no - 1) + dst_pos * 2, v_str(src_str_no - 1) + src_pos * 2, len*2);
*(v_str(dst_str_no - 1) + dst_pos * 2 + len*2) = '\0';
v_strncpy(dst_str_no - 1, dst_pos, src_str_no - 1, src_pos, len);
DEBUG_COMMAND("ME %d,%d,%d,%d,%d:\n",dst_str_no, dst_pos, src_str_no, src_pos, len);
}
@@ -262,14 +267,13 @@ void commandMF() {
int dst_no = getCaliValue();
int key_no = getCaliValue();
int start_pos = getCaliValue();
char *start = v_str(dst_no - 1) + start_pos * 2;
char *pos = strstr(start, v_str(key_no - 1));
int pos = v_strstr(dst_no - 1, start_pos, v_str(key_no - 1));
if (pos == NULL) {
if (pos < 0) {
sysVar[0] = 255;
} else {
*var = (pos - start) / 2;
*var = pos;
sysVar[0] = 0;
}
@@ -376,26 +380,16 @@ void commandMN() {
int num = getCaliValue();
int *var = getCaliVariable();
int i, len;
char *b;
const char *b;
switch(no) {
case 0:
/* 文字列を配列に変換する */
len = v_strlen(num -1);
b = v_str(num -1);
for (i = 0; i < len; i++) {
*var = *b;
var++; b++;
}
*var = 0;
sysVar[0] = v_strToVars(num - 1, var);
break;
case 1:
/* 配列を文字列に変換する */
b = v_str(num -1);
while(*var) {
*b = *var; b++; var++;
}
*b = '\0';
v_strFromVars(num - 1, var);
break;
default:
WARNING("UnKnown MN command(%d)\n", no);
+3 -3
View File
@@ -46,13 +46,13 @@ struct _FONT {
void (*sel_font)(int type, int size);
struct agsurface *(*get_glyph)(unsigned char *str);
struct agsurface *(*get_glyph)(const unsigned char *str);
int (*draw_glyph)(int x, int y, unsigned char *str, int col);
int (*draw_glyph)(int x, int y, const unsigned char *str, int col);
boolean (*self_drawable)();
int (*codeconv[FONTTYPEMAX])(unsigned char **msg);
int (*codeconv[FONTTYPEMAX])(const unsigned char **msg);
};
typedef struct _FONT FONT;
+6 -6
View File
@@ -60,7 +60,7 @@ static FONT *this;
static void pixmap2comimg(BYTE *src, int x, int y, int w, int h, int src_bpl);
static void pixmapmono2comimg(BYTE *src, int x, int y, int w, int h, int src_bpl);
static int toUnicode(unsigned char **msg) {
static int toUnicode(const unsigned char **msg) {
int code;
if (**msg >= 0xa0 && **msg <= 0xdf) {
@@ -74,7 +74,7 @@ static int toUnicode(unsigned char **msg) {
return code;
}
static int toSJIS(unsigned char **msg) {
static int toSJIS(const unsigned char **msg) {
int code;
if (**msg >= 0xa0 && **msg <= 0xdf) {
@@ -88,7 +88,7 @@ static int toSJIS(unsigned char **msg) {
return code;
}
static int toSJIS0213(unsigned char **msg) {
static int toSJIS0213(const unsigned char **msg) {
int code;
if (**msg >= 0xa0 && **msg <= 0xdf) {
@@ -231,14 +231,14 @@ static void clear_canvas(void) {
memset(img_glyph.pixel, 0, GLYPH_PIXMAP_WIDTH * GLYPH_PIXMAP_HEIGHT);
}
static agsurface_t *font_ttf_get_glyph(unsigned char *_msg) {
static agsurface_t *font_ttf_get_glyph(const unsigned char *_msg) {
FT_GlyphSlot slot;
FT_UShort code;
FT_Error err;
FT_Pixel_Mode pixelmode;
FT_Int loadflag;
int x = 0;
unsigned char *msg = _msg;
const unsigned char *msg = _msg;
if (fontset == NULL) return &img_glyph;
@@ -300,7 +300,7 @@ static agsurface_t *font_ttf_get_glyph(unsigned char *_msg) {
return &img_glyph;
}
static int font_ttf_draw_glyph(int x, int y, unsigned char *str, int col) {
static int font_ttf_draw_glyph(int x, int y, const unsigned char *str, int col) {
return 0;
}
+6 -2
View File
@@ -69,10 +69,12 @@ static void font_sdlttf_sel_font(int type, int size) {
}
}
static agsurface_t *font_sdlttf_get_glyph(unsigned char *msg) {
static agsurface_t *font_sdlttf_get_glyph(const unsigned char *msg) {
static SDL_Surface *fs;
static agsurface_t result;
if (!fontset)
return NULL;
if (fs) {
SDL_FreeSurface(fs);
fs = NULL;
@@ -140,7 +142,7 @@ static void sdl_drawAntiAlias_8bpp(int dstx, int dsty, SDL_Surface *src, unsigne
SDL_UnlockSurface(sdl_dib);
}
static int font_sdlttf_draw_glyph(int x, int y, unsigned char *str, int cl) {
static int font_sdlttf_draw_glyph(int x, int y, const unsigned char *str, int cl) {
SDL_Surface *fs;
SDL_Rect r_src, r_dst;
int w, h, maxy;
@@ -148,6 +150,8 @@ static int font_sdlttf_draw_glyph(int x, int y, unsigned char *str, int cl) {
if (!*str)
return 0;
if (!fontset)
return 0;
conv = sjis2lang(str);
if (this->antialiase_on) {
+2 -2
View File
@@ -151,7 +151,7 @@ static agsurface_t *get_drawn_glyph(const char *str, int w) {
return dst;
}
static agsurface_t *font_x11_get_glyph(unsigned char *str) {
static agsurface_t *font_x11_get_glyph(const unsigned char *str) {
agsurface_t *dst;
int w;
BYTE *conv;
@@ -182,7 +182,7 @@ static agsurface_t *font_x11_get_glyph(unsigned char *str) {
return &img_glyph;
}
static int font_x11_draw_glyph(int x, int y, unsigned char *str, int col) {
static int font_x11_draw_glyph(int x, int y, const unsigned char *str, int col) {
int w;
BYTE *conv;
+200
View File
@@ -0,0 +1,200 @@
/*
* gameresource.c Game Resource (*.gr) file
*
* Copyright (C) 1997-1998 Masaki Chikama (Wren) <chikama@kasumi.ipl.mech.nagoya-u.ac.jp>
* 1998- <masaki-c@is.aist-nara.ac.jp>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <ctype.h>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include "gameresource.h"
#include "system.h"
static void storeDataName(GameResource *gr, int type, int no, char *src) {
gr->game_fname[type][no] = strdup(src);
gr->cnt[type] = max(no + 1, gr->cnt[type]);
}
static void storeSaveName(GameResource *gr, int no, char *src) {
char *home_dir = "";
char *path = NULL;
if (*src == '~') {
home_dir = getenv("HOME");
if (NULL == (path = malloc(strlen(home_dir) + strlen(src) + 1))) {
NOMEMERR();
}
sprintf(path, "%s%s", home_dir, src+1);
gr->save_fname[no] = strdup(path);
src = path;
} else {
gr->save_fname[no] = strdup(src);
}
if (no == 0) {
char *b = strrchr(src, '/');
if (b == NULL) {
SYSERROR("Illigal save filename %s\n", src);
}
*b = '\0';
gr->save_path = strdup(src);
}
if (path) free(path);
}
static boolean initFromDir(GameResource *gr) {
char cwd[256], path[256];
getcwd(cwd, 255);
DIR *dir = opendir(".");
if(!dir)
SYSERROR("Game Resource File open failed\n");
struct dirent* d;
while ((d = readdir(dir))) {
char *filename = d->d_name;
int len = strlen(filename);
sprintf(path, "%s/%s", cwd, filename);
if (strcasecmp(filename, "adisk.ald") == 0) {
storeDataName(gr, DRIFILE_SCO, 0, path);
} else if (strcasecmp(filename, "system39.ain") == 0) {
gr->ain = strdup(filename);
} else if (strcasecmp(filename + len - 4, ".ald") == 0) {
int dno = toupper(filename[len - 5]) - 'A';
if (dno < 0 || dno >= DRIFILEMAX) continue;
switch (toupper(filename[len - 6])) {
case 'S':
storeDataName(gr, DRIFILE_SCO, dno, path);
break;
case 'G':
storeDataName(gr, DRIFILE_CG, dno, path);
break;
case 'W':
storeDataName(gr, DRIFILE_WAVE, dno, path);
break;
case 'M':
storeDataName(gr, DRIFILE_MIDI, dno, path);
break;
case 'D':
storeDataName(gr, DRIFILE_DATA, dno, path);
break;
case 'R':
storeDataName(gr, DRIFILE_RSC, dno, path);
break;
case 'B':
storeDataName(gr, DRIFILE_BGM, dno, path);
break;
}
}
}
for (int i = 0; i < SAVE_MAXNUMBER; i++) {
sprintf(path, "%s/%c%s", cwd, 'a' + i, "sleep.asd");
storeSaveName(gr, i, path);
}
return (gr->cnt[DRIFILE_SCO] > 0) ? TRUE : FALSE;
}
static void trimRight(char *str) {
for (char *p = str + strlen(str) - 1; p >= str && isspace(*p); p--)
*p = '\0';
}
static boolean initFromFile(GameResource *gr, FILE *fp, const char *gr_fname) {
int linecnt = 0, dno;
char line[256];
char key[256], path[256];
while (fgets(line, 255, fp) != NULL) {
linecnt++;
if (line[0] == '#') continue;
path[0] = '\0';
sscanf(line, "%s %[^\n]", key, path);
if (path[0] == '\0') continue;
trimRight(path);
if (0 == strncmp(key, "Scenario", 8)) {
dno = key[8] - 'A';
if (dno < 0 || dno >= DRIFILEMAX) goto errexit;
storeDataName(gr, DRIFILE_SCO, dno, path);
} else if (0 == strncmp(key, "Graphics", 8)) {
dno = key[8] - 'A';
if (dno < 0 || dno >= DRIFILEMAX) goto errexit;
storeDataName(gr, DRIFILE_CG, dno, path);
} else if (0 == strncmp(key, "Wave", 4)) {
dno = key[4] - 'A';
if (dno < 0 || dno >= DRIFILEMAX) goto errexit;
storeDataName(gr, DRIFILE_WAVE, dno, path);
} else if (0 == strncmp(key, "Midi", 4)) {
dno = key[4] - 'A';
if (dno < 0 || dno >= DRIFILEMAX) goto errexit;
storeDataName(gr, DRIFILE_MIDI, dno, path);
} else if (0 == strncmp(key, "Data", 4)) {
dno = key[4] - 'A';
if (dno < 0 || dno >= DRIFILEMAX) goto errexit;
storeDataName(gr, DRIFILE_DATA, dno, path);
} else if (0 == strncmp(key, "Resource", 8)) {
dno = key[8] - 'A';
if (dno < 0 || dno >= DRIFILEMAX) goto errexit;
storeDataName(gr, DRIFILE_RSC, dno, path);
} else if (0 == strncmp(key, "BGM", 3)) {
dno = key[3] - 'A';
if (dno < 0 || dno >= DRIFILEMAX) goto errexit;
storeDataName(gr, DRIFILE_BGM, dno, path);
} else if (0 == strncmp(key, "Save", 4)) {
dno = key[4] - 'A';
if (dno < 0 || dno >= DRIFILEMAX) goto errexit;
storeSaveName(gr, dno, path);
} else if (0 == strncmp(key, "Ain", 3)) {
gr->ain = strdup(path);
} else if (0 == strncmp(key, "WAIA", 4)) {
gr->wai = strdup(path);
} else if (0 == strncmp(key, "BGIA", 4)) {
gr->bgi = strdup(path);
} else if (0 == strncmp(key, "SACT01", 6)) {
gr->sact01 = strdup(path);
} else if (0 == strncmp(key, "Init", 4)) {
gr->init = strdup(path);
} else if (0 == strncmp(key, "ALK", 3)) {
dno = key[4] - '0';
if (dno < 0 || dno >= 10) goto errexit;
gr->alk[dno] = strdup(path);
} else {
goto errexit;
}
}
return TRUE;
errexit:
SYSERROR("Illigal resource at line(%d) file<%s>\n", linecnt, gr_fname);
return FALSE;
}
boolean initGameResource(GameResource *gr, const char *gr_fname) {
memset(gr, 0, sizeof(GameResource));
FILE *fp = fopen(gr_fname, "r");
if (!fp)
return initFromDir(gr);
boolean result = initFromFile(gr, fp, gr_fname);
fclose(fp);
return result;
}
+45
View File
@@ -0,0 +1,45 @@
/*
* gameresource.h Game Resource (*.gr) file
*
* Copyright (C) 1997-1998 Masaki Chikama (Wren) <chikama@kasumi.ipl.mech.nagoya-u.ac.jp>
* 1998- <masaki-c@is.aist-nara.ac.jp>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef __GAMERESOURCE_H__
#define __GAMERESOURCE_H__
#include "portab.h"
#include "ald_manager.h"
#include "savedata.h"
typedef struct {
char *game_fname[DRIFILETYPEMAX][DRIFILEMAX];
int cnt[DRIFILETYPEMAX];
char *save_path;
char *save_fname[SAVE_MAXNUMBER];
char *ain;
char *wai;
char *bgi;
char *sact01;
char *init;
char *alk[10];
} GameResource;
boolean initGameResource(GameResource *gr, const char *gr_fname);
#endif /* !__GAMERESOURCE_H__ */
+66
View File
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2020 <KichikuouChrome@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#undef NDEBUG
#include "gameresource.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void gameresource_test(void) {
#ifdef _WIN32
_putenv("HOME=/home/kichikuou");
#else
setenv("HOME", "/home/kichikuou", 1);
#endif
GameResource gr;
assert(initGameResource(&gr, "testdata/test.gr"));
assert(gr.cnt[DRIFILE_SCO] == 1);
assert(strcmp(gr.game_fname[DRIFILE_SCO][0], "fooSA.ALD") == 0);
assert(gr.cnt[DRIFILE_CG] == 2);
assert(strcmp(gr.game_fname[DRIFILE_CG][0], "fooGA.ALD") == 0);
assert(strcmp(gr.game_fname[DRIFILE_CG][1], "fooGB.ALD") == 0);
assert(gr.cnt[DRIFILE_WAVE] == 26);
assert(strcmp(gr.game_fname[DRIFILE_WAVE][0], "fooWA.ALD") == 0);
for (int i = 1; i <= 24; i++)
assert(gr.game_fname[DRIFILE_WAVE][i] == NULL);
assert(strcmp(gr.game_fname[DRIFILE_WAVE][25], "fooWZ.ALD") == 0);
assert(gr.cnt[DRIFILE_MIDI] == 3);
assert(strcmp(gr.game_fname[DRIFILE_MIDI][2], "fooMC.ALD") == 0);
assert(strcmp(gr.game_fname[DRIFILE_DATA][0], "file name with whitespaces") == 0);
assert(strcmp(gr.game_fname[DRIFILE_RSC][0], "this line has whitespaces at end of line") == 0);
assert(strcmp(gr.game_fname[DRIFILE_BGM][0], "/path/to/fooBA.ALD") == 0);
assert(strcmp(gr.ain, "System39.ain") == 0);
assert(strcmp(gr.wai, "foo_WA.WAI") == 0);
assert(strcmp(gr.bgi, "foo_BA.BGI") == 0);
assert(strcmp(gr.sact01, "SACTEFAM.KLD") == 0);
assert(strcmp(gr.init, "System39.ini") == 0);
assert(strcmp(gr.alk[0], "0.alk") == 0);
for (int i = 1; i <= 8; i++)
assert(gr.alk[i] == NULL);
assert(strcmp(gr.alk[9], "9.alk") == 0);
assert(strcmp(gr.save_fname[0], "/home/kichikuou/save/foo_sa.asd") == 0);
assert(strcmp(gr.save_fname[25], "/tmp/foo_sz.asd") == 0);
// save_path is determined based on save_fname[0].
assert(strcmp(gr.save_path, "/home/kichikuou/save") == 0);
}
+2 -2
View File
@@ -612,7 +612,7 @@ static BYTE hankakutable[3][192][2] = {{
{0x83, 0xff}
}};
BYTE *zen2han(BYTE *src) {
BYTE *zen2han(const BYTE *src) {
BYTE c0, c1;
char *dst, *_dst;
@@ -644,7 +644,7 @@ BYTE *zen2han(BYTE *src) {
return _dst;
}
BYTE *han2zen(BYTE *src) {
BYTE *han2zen(const BYTE *src) {
BYTE c0;
BYTE *dst, *_dst;
BYTE *kindex;
+73
View File
@@ -0,0 +1,73 @@
/*
* Copyright (C) 2020 <KichikuouChrome@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <jpeglib.h>
#undef ERROR
#undef max
#undef min
#include "config.h"
#include "system.h"
#include "ags.h"
#include "jpeg.h"
boolean jpeg_checkfmt(BYTE *data) {
return data[0] == 0xff && data[1] == 0xd8;
}
cgdata *jpeg_extract(BYTE *data, size_t size) {
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
// TODO: Error handling
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
jpeg_mem_src(&cinfo, data, size);
if (jpeg_read_header(&cinfo, TRUE) != JPEG_HEADER_OK) {
WARNING("jpeg_read_header failed\n");
jpeg_destroy_decompress(&cinfo);
return NULL;
}
jpeg_start_decompress(&cinfo);
cgdata *cg = calloc(1, sizeof(cgdata));
cg->type = ALCG_JPEG;
cg->width = cinfo.output_width;
cg->height = cinfo.output_height;
cg->pic = malloc(sizeof(WORD) * cg->width * cg->height);
int row_stride = cinfo.output_width * cinfo.output_components;
JSAMPARRAY buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
WORD *dst = (WORD *)cg->pic;
while (cinfo.output_scanline < cinfo.output_height) {
jpeg_read_scanlines(&cinfo, buffer, 1);
for (int x = 0; x < cinfo.output_width; x++)
*dst++ = PIX16(buffer[0][x * 3], buffer[0][x * 3 + 1], buffer[0][x * 3 + 2]);
}
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
return cg;
}
+28
View File
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2020 <KichikuouChrome@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef __JPEG_H__
#define __JPEG_H__
#include "cg.h"
extern boolean jpeg_checkfmt(BYTE *data);
extern cgdata *jpeg_extract(BYTE *data, size_t size);
#endif // __JPEG_H__
+16 -7
View File
@@ -58,7 +58,7 @@ static boolean nextLineIsAfterKaigyou = FALSE;
/* Private Methods */
static void drawLineFrame(Bcom_WindowInfo *info);
static void copyMsgToStrVar(char *m);
static void copyMsgToStrVar(const char *m);
static void msgget_at_r();
static void msgget_at_a();
@@ -108,7 +108,7 @@ void msg_setStringDecorationType(int type) {
msgDecorateType = type;
}
void msg_putMessage(char *m) {
void msg_putMessage(const char *m) {
int w;
MyRectangle adj;
@@ -130,6 +130,7 @@ void msg_putMessage(char *m) {
ags_setFont(msg.MsgFont, msg.MsgFontSize);
switch(msgDecorateType) {
case 0:
default:
adj.x = 0; adj.y = 0; adj.width = 0; adj.height = 0;
break;
case 1:
@@ -145,6 +146,12 @@ void msg_putMessage(char *m) {
adj.x = 0; adj.y = 0; adj.width = 1; adj.height = 1;
break;
case 4:
ags_drawString(msgcur.x -1, msgcur.y, m, msgDecorateColor);
ags_drawString(msgcur.x +1, msgcur.y, m, msgDecorateColor);
ags_drawString(msgcur.x, msgcur.y -1, m, msgDecorateColor);
ags_drawString(msgcur.x, msgcur.y +1, m, msgDecorateColor);
adj.x = -1; adj.y = -1; adj.width = 2; adj.height = 2;
break;
case 6:
ags_drawString(msgcur.x +1, msgcur.y, m, msg.MsgFontColor);
adj.x = 0; adj.y = 0; adj.width = 1; adj.height = 0;
@@ -157,11 +164,13 @@ void msg_putMessage(char *m) {
ags_drawString(msgcur.x +1, msgcur.y +1, m, msg.MsgFontColor);
adj.x = 0; adj.y = 0; adj.width = 1; adj.height = 1;
break;
case 9:
case 10:
adj.x = 0; adj.y = 0; adj.width = 0; adj.height = 0;
break;
default:
ags_drawString(msgcur.x -1, msgcur.y , m, msgDecorateColor);
ags_drawString(msgcur.x +1, msgcur.y , m, msgDecorateColor);
ags_drawString(msgcur.x , msgcur.y -1, m, msgDecorateColor);
ags_drawString(msgcur.x , msgcur.y +1, m, msgDecorateColor);
ags_drawString(msgcur.x +2, msgcur.y +2, m, msgDecorateColor);
adj.x = -1; adj.y = -1; adj.width = 3; adj.height = 3;
break;
}
@@ -339,7 +348,7 @@ static void drawLineFrame(Bcom_WindowInfo *i) {
ags_updateArea(i->x -8, i->y -8, i->width +16, i->height +16);
}
static void copyMsgToStrVar(char *m) {
static void copyMsgToStrVar(const char *m) {
if (v_strlen(msg.mg_curStrVarNo -1) == 0) {
v_strcpy(msg.mg_curStrVarNo -1, m);
} else {
+1 -1
View File
@@ -32,7 +32,7 @@ extern void msg_init();
extern void msg_setFontSize(int size);
extern void msg_setStringDecorationColor(int col);
extern void msg_setStringDecorationType(int type);
extern void msg_putMessage(char *msg);
extern void msg_putMessage(const char *msg);
extern void msg_nextLine();
extern void msg_nextPage(boolean clear);
extern void msg_hitAnyKey();
+5 -5
View File
@@ -52,8 +52,8 @@ MG コマンド: 表示時の ZH に依存
*/
/* defined in hankaku.c */
extern BYTE *zen2han(BYTE *src);
extern BYTE *han2zen(BYTE *src);
extern BYTE *zen2han(const BYTE *src);
extern BYTE *han2zen(const BYTE *src);
/* defined by hankan2sjis.c */
extern char *hankana2sjis(int index);
/* defined by cmd_check.c */
@@ -124,8 +124,8 @@ char* sys_getConvString(char term) {
}
/* 選択肢・通常メッセージ振り分け */
void sys_addMsg(char *str) {
char *msg = NULL;
void sys_addMsg(const char *str) {
const char *msg = NULL;
switch(msg_msgHankakuMode) {
case 0:
@@ -153,7 +153,7 @@ void sys_addMsg(char *str) {
}
if (msg && msg_msgHankakuMode < 2) {
free(msg);
free((char *)msg);
}
}
+2 -2
View File
@@ -45,7 +45,7 @@ extern int *getCaliVariable();
extern int *getVariable();
extern char *sys_getString(char term);
extern char *sys_getConvString(char term);
extern void sys_addMsg(char *str);
extern void sys_addMsg(const char *str);
extern void sys_setHankakuMode(int mode);
extern char *sys_getConstString();
@@ -110,7 +110,7 @@ typedef struct {
/* メッセージ関連 */
msg_t msg;
boolean is_msg_out; /* 通常メッセージを表示するか */
void (*msgout)(char *msg); // 通常以外(DLL等)のメッセージ表示関数
void (*msgout)(const char *msg); // 通常以外(DLL等)のメッセージ表示関数
/* 選択肢関連 */
sel_t sel;
+18 -17
View File
@@ -185,7 +185,8 @@ int save_save_str_with_file(char *filename, int start, int cnt) {
*tmp = 0;
for (i = 0; i < cnt; i++) {
strncpy(tmp, v_str(start + i - 1), strvar_len - 1);
tmp += v_strlen(start + i - 1) + 1;
tmp[strvar_len - 1] = '\0';
tmp += strlen(tmp) + 1;
}
@@ -241,8 +242,8 @@ int save_load_str_with_file(char *filename, int start, int cnt) {
status = SAVE_LOADOK;
}
for (i = 0; i < cnt; i++) {
strncpy(v_str(start + i - 1), tmp, strvar_len);
tmp += v_strlen(start + i - 1) + 1;
v_strcpy(start + i - 1, tmp);
tmp += strlen(tmp) + 1;
}
fclose(fp);
free(_tmp);
@@ -290,7 +291,7 @@ int save_loadPartial(int no, int page, int offset, int cnt) {
cnt = min(cnt, SYSVAR_MAX - offset);
var = sysVar + offset;
} else {
cnt = min(cnt, arrayVarBuffer[page - 1].max - offset);
cnt = min(cnt, arrayVarBuffer[page - 1].size - offset);
var = arrayVarBuffer[page - 1].value + offset;
}
@@ -348,7 +349,7 @@ int save_savePartial(int no, int page, int offset, int cnt) {
} else {
if (arrayVarBuffer[page - 1].saveflag == FALSE)
goto errexit;
cnt = min(cnt, arrayVarBuffer[page - 1].max - offset);
cnt = min(cnt, arrayVarBuffer[page - 1].size - offset);
var = arrayVarBuffer[page - 1].value + offset;
}
@@ -599,7 +600,8 @@ static void *saveStrVar(Ald_strVarHdr *head) {
*tmp = 0;
for (i = 0; i < strvar_cnt; i++) {
strncpy(tmp, v_str(i), strvar_len - 1);
tmp += v_strlen(i) + 1;
tmp[strvar_len - 1] = '\0';
tmp += strlen(tmp) + 1;
}
head->size = tmp - _tmp;
head->count = strvar_cnt;
@@ -618,8 +620,8 @@ static void loadStrVar(char *buf) {
v_initStringVars(cnt, max);
buf += sizeof(Ald_strVarHdr);
for (i = 0; i < cnt; i++) {
strncpy(v_str(i), buf, max - 1);
buf += v_strlen(i) + 1;
v_strcpy(i, buf);
buf += strlen(buf) + 1;
}
}
@@ -634,7 +636,7 @@ static void *saveSysVar(Ald_sysVarHdr *head, int page) {
} else if (!arrayVarBuffer[page - 1].saveflag) {
return NULL;
} else {
cnt = arrayVarBuffer[page - 1].max;
cnt = arrayVarBuffer[page - 1].size;
var = arrayVarBuffer[page - 1].value;
if (var == NULL)
return NULL;
@@ -672,7 +674,7 @@ static int loadSysVar(char *buf) {
cnt = savefile_sysvar_cnt = head->size / sizeof(WORD);
} else {
cnt = head->size / sizeof(WORD);
if (arrayVarBuffer[page - 1].max != cnt ||
if (arrayVarBuffer[page - 1].size < cnt ||
arrayVarBuffer[page - 1].value == NULL) {
/*
fprintf(stderr, "loadSysVar(): undef array\n");
@@ -755,11 +757,10 @@ static int saveGameData(int no, char *buf, int size) {
}
/* 指定ファイルからの画像の読み込み thanx tajiru@wizard */
BYTE* load_cg_with_file(char *filename, int *status){
BYTE* load_cg_with_file(char *filename, int *status, long *filesize){
int size;
FILE *fp;
static BYTE *tmp;
long filesize;
*status = 0;
@@ -768,20 +769,20 @@ BYTE* load_cg_with_file(char *filename, int *status){
}
fseek(fp, 0L, SEEK_END);
filesize = ftell(fp);
if (filesize == 0) {
*filesize = ftell(fp);
if (*filesize == 0) {
*status = SAVE_LOADERR; return NULL;
}
tmp = (char *)malloc(filesize);
tmp = (char *)malloc(*filesize);
if (tmp == NULL) {
WARNING("Out of memory\n");
*status = SAVE_LOADERR; return NULL;
}
fseek(fp, 0L, SEEK_SET);
size = fread(tmp, 1, filesize,fp);
size = fread(tmp, 1, *filesize,fp);
if (size != filesize) {
if (size != *filesize) {
*status = SAVE_LOADSHORTAGE;
} else {
*status = SAVE_LOADOK;
+1 -1
View File
@@ -124,7 +124,7 @@ extern int save_save_var_with_file(char *filename, int *start, int cnt);
extern int save_load_var_with_file(char *filename, int *start, int cnt);
extern int save_save_str_with_file(char *filename, int start, int cnt);
extern int save_load_str_with_file(char *filename, int start, int cnt);
extern BYTE* load_cg_with_file(char *file,int *status);
extern BYTE* load_cg_with_file(char *file, int *status, long *filesize);
extern void save_set_path(char *path);
extern void save_register_file(char *name, int index);
extern char* save_get_file(int index);
+2 -3
View File
@@ -53,7 +53,7 @@ extern void sdl_setPallet(Pallet256 *pal, int src, int cnt);
extern void sdl_drawRectangle(int x, int y, int w, int h, int cl);
extern void sdl_fillRectangle(int x, int y, int w, int h, unsigned long c);
extern void sdl_drawLine(int x1, int y1, int x2, int y2, unsigned long col);
extern int sdl_drawString(int x, int y, char *msg, unsigned long col);
extern int sdl_drawString(int x, int y, const char *msg, unsigned long col);
extern void sdl_copyArea(int sx,int sy, int w, int h, int dx, int dy);
extern void sdl_drawTT(int x,int y,int w,int h,const char *bitmap,int ww, boolean antialiased);
extern void sdl_copyAreaSP(int sx, int sy, int w, int h, int dx, int dy, int sp);
@@ -102,7 +102,6 @@ extern void sdl_mainIteration();
extern boolean RawKeyInfo[];
extern void sdl_sleep(int msec);
extern void sdl_wait_vsync();
extern void sdl_sync();
/* 初期化関係 */
#define GraphicsInitilize() sdl_Initilize()
@@ -116,7 +115,7 @@ extern void sdl_sync();
#define GetDIB() sdl_getDIB()
/* 画面更新 */
#define DspDeviceSync() sdl_sync()
#define DspDeviceSync()
#define UpdateArea(src,dst) sdl_updateArea((src),(dst))
#define FullScreen(on) sdl_FullScreen(on)
+12 -12
View File
@@ -82,18 +82,18 @@ static SDL_Cursor *init_system_cursor(const char *image[]) {
/* mouse cursur の初期化 */
void sdl_cursor_init(void) {
cursor[IDC_ARROW] = init_system_cursor(cursor_arrow);
cursor[IDC_CROSS] = init_system_cursor(cursor_cross);
cursor[IDC_IBEAM] = init_system_cursor(cursor_ibeam);
cursor[IDC_NO] = init_system_cursor(cursor_no);
cursor[IDC_SIZE] = init_system_cursor(cursor_move);
cursor[IDC_SIZEALL] = init_system_cursor(cursor_move);
cursor[IDC_SIZENESW] = init_system_cursor(cursor_size_r);
cursor[IDC_SIZENS] = init_system_cursor(cursor_size_v);
cursor[IDC_SIZENWSE] = init_system_cursor(cursor_size_l);
cursor[IDC_SIZEWE] = init_system_cursor(cursor_size_h);
cursor[IDC_UPARROW] = init_system_cursor(cursor_uparrow);
cursor[IDC_WAIT] = init_system_cursor(cursor_busy);
cursor[CURSOR_ARROW] = init_system_cursor(cursor_arrow);
cursor[CURSOR_CROSS] = init_system_cursor(cursor_cross);
cursor[CURSOR_IBEAM] = init_system_cursor(cursor_ibeam);
cursor[CURSOR_NO] = init_system_cursor(cursor_no);
cursor[CURSOR_SIZE] = init_system_cursor(cursor_move);
cursor[CURSOR_SIZEALL] = init_system_cursor(cursor_move);
cursor[CURSOR_SIZENESW] = init_system_cursor(cursor_size_r);
cursor[CURSOR_SIZENS] = init_system_cursor(cursor_size_v);
cursor[CURSOR_SIZENWSE] = init_system_cursor(cursor_size_l);
cursor[CURSOR_SIZEWE] = init_system_cursor(cursor_size_h);
cursor[CURSOR_UPARROW] = init_system_cursor(cursor_uparrow);
cursor[CURSOR_WAIT] = init_system_cursor(cursor_busy);
}
boolean sdl_cursorNew(BYTE* data, int no, CursorImage *cursorImage, TCursorDirEntry *cursordirentry) {
+1 -1
View File
@@ -412,7 +412,7 @@ static void sdl_drawAntiAlias_8bpp(int dstx, int dsty, agsurface_t *src, unsigne
SDL_UnlockSurface(sdl_dib);
}
int sdl_drawString(int x, int y, char *msg, unsigned long col) {
int sdl_drawString(int x, int y, const char *msg, unsigned long col) {
int w;
sdl_pal_check();
-10
View File
@@ -428,13 +428,3 @@ void sdl_restoreRegion(void *psrc, int x, int y) {
sdl_putRegion(src, x ,y);
SDL_FreeSurface(src);
}
void sdl_sync() {
// imageXX等でsurface内を直接操作する際に、本当はlock/unlockで
// はさまないといけないんだけど、lockすればそれまでキューに入って
// いた SDL内部の処理がすべて終ると予想されるのでXsyncと同様の
// 効果があると思う。しかしUnlockしているので非同期でimageXXの処理中
// にSDLの描画命令が入る可能性もあるが、X11ではたぶん大丈夫?
SDL_LockSurface(sdl_dib);
SDL_UnlockSurface(sdl_dib);
}
+1
View File
@@ -116,6 +116,7 @@ static void window_init(void) {
#endif
#ifdef __ANDROID__
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
SDL_SetHint(SDL_HINT_ORIENTATIONS, "LandscapeLeft LandscapeRight");
Uint32 flags = SDL_WINDOW_FULLSCREEN;
#else
+36
View File
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2020 <KichikuouChrome@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
void gameresource_test(void);
void sys_error(char *format, ...) {
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
exit(1);
}
int main() {
gameresource_test();
return 0;
}
+22
View File
@@ -0,0 +1,22 @@
# This line is a comment.
ScenarioA fooSA.ALD
GraphicsA fooGA.ALD
GraphicsB fooGB.ALD
WaveA fooWA.ALD
WaveZ fooWZ.ALD
MidiC fooMC.ALD
DataA file name with whitespaces
ResourceA this line has whitespaces at end of line
BGMA /path/to/fooBA.ALD
Ain System39.ain
WAIA foo_WA.WAI
BGIA foo_BA.BGI
SACT01 SACTEFAM.KLD
Init System39.ini
ALK00 0.alk
ALK09 9.alk
SaveA ~/save/foo_sa.asd
SaveZ /tmp/foo_sz.asd
+160 -42
View File
@@ -25,52 +25,57 @@
#include <stdlib.h>
#include <string.h>
#include "portab.h"
#include "utfsjis.h"
#include "variable.h"
#include "xsystem35.h"
/* システム変数 */
int *sysVar;
int sysVar[SYSVAR_MAX];
/* 配列変数の情報 */
arrayVarStruct *sysVarAttribute;
arrayVarStruct sysVarAttribute[SYSVAR_MAX];
/* 配列本体 */
arrayVarBufferStruct *arrayVarBuffer;
arrayVarBufferStruct arrayVarBuffer[ARRAYVAR_PAGEMAX];
/* 64bit変数 */
double longVar[SYSVARLONG_MAX];
/* 文字列変数 */
static char *strVar;
static char **strVar;
/* 文字列変数の属性(最大,1つあたりの大きさ) */
int strvar_cnt = STRVAR_MAX;
int strvar_len = STRVAR_LEN;
static char *advance(const char *s, int n) {
while (*s && n > 0) {
s += (CHECKSJIS1BYTE(*s) && *(s + 1)) ? 2 : 1;
n--;
}
return (char *)s;
}
/* 配列バッファの確保 DC ,page = 1~ */
extern boolean v_allocateArrayBuffer(int page, int size, boolean flg) {
void *buf;
extern boolean v_allocateArrayBuffer(int page, int size, boolean saveflag) {
if (page <= 0 || page > 256) { return false; }
if (size <= 0 || size > 65536) { return false; }
if (NULL == (buf = malloc(size * sizeof(int) + 257))) {
void *buf = arrayVarBuffer[page - 1].value;
if (buf != NULL)
buf = realloc(buf, size * sizeof(int));
else
buf = calloc(size, sizeof(int));
if (!buf)
NOMEMERR();
}
memset(buf, 0, size * sizeof(int) + 257);
if (arrayVarBuffer[page - 1].value != NULL) {
int len = min(size, arrayVarBuffer[page - 1].max);
memcpy(buf, arrayVarBuffer[page - 1].value, len * sizeof(int));
}
arrayVarBuffer[page - 1].value = buf;
arrayVarBuffer[page - 1].max = size;
arrayVarBuffer[page - 1].saveflag = flg;
arrayVarBuffer[page - 1].size = size;
arrayVarBuffer[page - 1].saveflag = saveflag;
return true;
}
/* 配列変数の割り当て DS */
extern boolean v_defineArrayVar(int datavar, int *pointvar, int offset, int page) {
if (datavar < 0 || datavar > SYSVAR_MAX - 1) { return false; }
if (page < 0 || page > ARRAYVAR_PAGEMAX - 1) { return false; }
if (offset < 0 || offset > arrayVarBuffer[page - 1].max - 1) { return false; }
if (datavar < 0 || datavar > SYSVAR_MAX - 1) { return false; }
if (page < 0 || page > ARRAYVAR_PAGEMAX - 1) { return false; }
if (offset < 0 || offset >= arrayVarBuffer[page - 1].size) { return false; }
sysVarAttribute[datavar].pointvar = pointvar;
sysVarAttribute[datavar].page = page;
@@ -84,11 +89,6 @@ extern boolean v_releaseArrayVar(int datavar) {
return true;
}
/* 指定ページの最大変数の取得 page = 1~ */
extern int v_getArrayBufferCnt(int page) {
return arrayVarBuffer[page - 1].max;
}
/* 指定ページは使用中 page = 1~ */
extern boolean v_getArrayBufferStatus(int page) {
return (arrayVarBuffer[page - 1].value != NULL) ? true : false;
@@ -96,46 +96,164 @@ extern boolean v_getArrayBufferStatus(int page) {
/* 文字列変数の再初期化 */
extern void v_initStringVars(int cnt,int len) {
strVar = realloc(strVar, cnt * len);
for (int i = cnt + 1; i < strvar_cnt; i++) {
if (strVar[i])
free(strVar[i]);
}
strVar = realloc(strVar, cnt * sizeof(char *));
if (strVar == NULL) {
NOMEMERR();
}
for (int i = strvar_cnt + 1; i < cnt; i++)
strVar[i] = NULL;
strvar_cnt = cnt;
strvar_len = len;
}
/* 変数の初期化 */
extern boolean v_initVars() {
sysVar = calloc(SYSVAR_MAX, sizeof(int));
sysVarAttribute = calloc(SYSVAR_MAX, sizeof(arrayVarStruct));
arrayVarBuffer = calloc(ARRAYVAR_PAGEMAX, sizeof(arrayVarBufferStruct));
strVar = calloc(STRVAR_MAX, STRVAR_LEN);
if (strVar == NULL || sysVar == NULL || sysVarAttribute == NULL || arrayVarBuffer == NULL) {
strVar = calloc(STRVAR_MAX, sizeof(char *));
if (strVar == NULL) {
NOMEMERR();
}
return true;
}
/* 文字変数への代入 */
char *v_strcpy(int no, const char *str) {
return strncpy(strVar + no * strvar_len, str, strvar_len - 1);
void v_strcpy(int no, const char *str) {
if (no < 0 || no >= strvar_cnt) {
WARNING("string index out of range: %d", no);
return;
}
if (strVar[no])
free(strVar[no]);
strVar[no] = strdup(str);
}
void v_strncpy(int dstno, int dstpos, int srcno, int srcpos, int len) {
if (dstno < 0 || dstno >= strvar_cnt) {
WARNING("string index out of range: %d", dstno);
return;
}
if (!strVar[dstno])
strVar[dstno] = strdup("");
char *buf = NULL;
const char *src;
if (srcno == dstno)
src = buf = strdup(strVar[srcno]);
else
src = v_str(srcno);
dstpos = advance(strVar[dstno], dstpos) - strVar[dstno]; // #chars -> #bytes
src = advance(src, srcpos);
len = advance(src, len) - src; // #chars -> #bytes
strVar[dstno] = realloc(strVar[dstno], dstpos + len + 1);
strncpy(strVar[dstno] + dstpos, src, len);
strVar[dstno][dstpos + len] = '\0';
if (buf)
free(buf);
}
/* 文字変数への接続 */
char *v_strcat(int no, const char *str) {
return strncat(strVar + no * strvar_len, str, strvar_len - 1);
void v_strcat(int no, const char *str) {
if (no < 0 || no >= strvar_cnt) {
WARNING("string index out of range: %d", no);
return;
}
if (!strVar[no]) {
strVar[no] = strdup(str);
return;
}
int len1 = strlen(strVar[no]);
int len2 = strlen(str);
strVar[no] = realloc(strVar[no], len1 + len2 + 1);
strcpy(strVar[no] + len1, str);
}
/* 文字変数の長さ */
size_t v_strlen(int no) {
return strlen(strVar + no * strvar_len);
if (no < 0 || no >= strvar_cnt) {
WARNING("string index out of range: %d", no);
return 0;
}
return strVar[no] ? sjis_count_char(strVar[no]) : 0;
}
/* 文字変数そのもの */
char *v_str(int no) {
return strVar + no * strvar_len;
const char *v_str(int no) {
if (no < 0 || no >= strvar_cnt) {
WARNING("string index out of range: %d", no);
return "";
}
return strVar[no] ? strVar[no] : "";
}
int v_strstr(int no, int start, const char *str) {
if (no < 0 || no >= strvar_cnt) {
WARNING("string index out of range: %d", no);
return -1;
}
if (!*str)
return 0;
if (!strVar[no])
return -1;
const char *p = advance(strVar[no], start);
const char *found = strstr(p, str);
if (!found)
return -1;
int n = start;
while (p < found) {
p += CHECKSJIS1BYTE(*p) ? 2 : 1;
n++;
}
return n;
}
void v_strFromVars(int no, const int *vars) {
if (no < 0 || no >= strvar_cnt) {
WARNING("string index out of range: %d", no);
return;
}
int len = 0;
for (const int *c = vars; *c; c++)
len += (*c < 256) ? 1 : 2;
if (strVar[no])
free(strVar[no]);
char *p = strVar[no] = malloc(len + 1);
for (const int *v = vars; *v; v++) {
if (*v < 256) {
*p++ = *v;
} else {
*p++ = *v & 0xff;
*p++ = *v >> 8;
}
}
*p = '\0';
}
int v_strToVars(int no, int *vars) {
if (no < 0 || no >= strvar_cnt) {
WARNING("string index out of range: %d", no);
return 0;
}
if (!strVar[no]) {
*vars = 0;
return 1;
}
int count = 0;
for (const char *p = strVar[no]; *p; p++, count++) {
vars[count] = *p & 0xff;
if (CHECKSJIS1BYTE(*p) && *(p + 1))
vars[count] |= (*++p & 0xff) << 8;
}
vars[count++] = 0;
return count;
}
#ifdef DEBUG
@@ -159,9 +277,9 @@ void debug_showvariable() {
for (i = 0; i < ARRAYVAR_PAGEMAX; i++) {
if (arrayVarBuffer[i].value != NULL) {
fprintf(fp, "ArrayPage[%d],max=%d\n",i,arrayVarBuffer[i].max);
fprintf(fp, "ArrayPage[%d],size=%d\n",i,arrayVarBuffer[i].size);
var = arrayVarBuffer[i].value;
for (j = 0; j < arrayVarBuffer[i].max; j+=10) {
for (j = 0; j < arrayVarBuffer[i].size; j+=10) {
for (k = 0; k < 10; k++) {
fprintf(fp, "%d,", *var); var++;
}
+13 -11
View File
@@ -37,7 +37,7 @@
#define ARRAYVAR_PAGEMAX 256
typedef struct {
int max;
int size;
boolean saveflag;
int *value;
} arrayVarBufferStruct;
@@ -48,21 +48,23 @@ typedef struct {
int offset;
} arrayVarStruct;
extern int *sysVar;
extern arrayVarStruct *sysVarAttribute;
extern arrayVarBufferStruct *arrayVarBuffer;
extern int sysVar[];
extern arrayVarStruct sysVarAttribute[];
extern arrayVarBufferStruct arrayVarBuffer[];
extern double longVar[];
extern boolean v_allocateArrayBuffer(int , int , boolean );
extern boolean v_defineArrayVar(int , int *, int , int );
extern boolean v_releaseArrayVar(int );
extern boolean v_allocateArrayBuffer(int page, int size, boolean saveflag);
extern boolean v_defineArrayVar(int datavar, int *pointvar, int offset, int page);
extern boolean v_releaseArrayVar(int datavar);
extern int v_getArrayBufferCnt(int page);
extern boolean v_getArrayBufferStatus(int page);
extern void v_initStringVars(int ,int );
extern boolean v_initVars();
extern char *v_strcpy(int no, const char *str);
extern char *v_strcat(int no, const char *str);
extern void v_strcpy(int no, const char *str);
extern void v_strncpy(int dstno, int dstpos, int srcno, int srcpos, int len);
extern void v_strcat(int no, const char *str);
extern size_t v_strlen(int no);
extern char *v_str(int no);
extern int v_strstr(int no, int start, const char *str);
extern void v_strFromVars(int no, const int *vars);
extern int v_strToVars(int no, int *vars);
extern const char *v_str(int no);
#endif /* !__VARIABLE__ */
+1 -1
View File
@@ -57,7 +57,7 @@ extern void Xcore_setForeground(unsigned long col);
extern void Xcore_drawRectangle(int x, int y, int w, int h, unsigned long col);
extern void Xcore_fillRectangle(int x, int y, int w, int h, unsigned long col);
extern void Xcore_drawLine(int x0, int y0, int x1, int y1, unsigned long col);
extern int Xcore_drawString(int x, int y, char *msg, unsigned long col);
extern int Xcore_drawString(int x, int y, const char *msg, unsigned long col);
extern void Xcore_copyArea(int sx, int sy, int w, int h, int dx, int dy);
// extern void Xcore_drawTT(int x, int y, int w, int h, const char *bitmap, int ww, boolean antialiased);
extern int Xcore_eCopyArea(int sx, int sy, int w, int h, int dx, int dy, int t,int opt, boolean flg, int spCol);
+13 -13
View File
@@ -97,25 +97,25 @@ void x11_init_cursor(void) {
maskPix[6] = XCreateBitmapFromData(x11_display, x11_window, maskbm6_bits,
maskbm6_width, maskbm6_height);
cursor[IDC_ARROW] = XCreatePixmapCursor(x11_display, curPix[0], maskPix[0],
cursor[CURSOR_ARROW] = XCreatePixmapCursor(x11_display, curPix[0], maskPix[0],
&black, &white, spot[0].x, spot[0].y);
cursor[IDC_CROSS] = XCreateFontCursor(x11_display, XC_tcross);
cursor[IDC_IBEAM] = cursor[IDC_ICON] = XCreateFontCursor(x11_display, XC_icon);
cursor[IDC_NO] = XCreateFontCursor(x11_display, XC_X_cursor);
cursor[IDC_SIZE] = XCreatePixmapCursor(x11_display, curPix[6], maskPix[6],
cursor[CURSOR_CROSS] = XCreateFontCursor(x11_display, XC_tcross);
cursor[CURSOR_IBEAM] = cursor[CURSOR_ICON] = XCreateFontCursor(x11_display, XC_icon);
cursor[CURSOR_NO] = XCreateFontCursor(x11_display, XC_X_cursor);
cursor[CURSOR_SIZE] = XCreatePixmapCursor(x11_display, curPix[6], maskPix[6],
&black, &white, spot[6].x, spot[6].y);
cursor[IDC_SIZEALL] = cursor[IDC_SIZE];
cursor[IDC_SIZENESW] = XCreatePixmapCursor(x11_display, curPix[4], maskPix[4],
cursor[CURSOR_SIZEALL] = cursor[CURSOR_SIZE];
cursor[CURSOR_SIZENESW] = XCreatePixmapCursor(x11_display, curPix[4], maskPix[4],
&black, &white, spot[4].x, spot[4].y);
cursor[IDC_SIZENS] = XCreatePixmapCursor(x11_display, curPix[2], maskPix[2],
cursor[CURSOR_SIZENS] = XCreatePixmapCursor(x11_display, curPix[2], maskPix[2],
&black, &white, spot[2].x, spot[2].y);
cursor[IDC_SIZENWSE] = XCreatePixmapCursor(x11_display, curPix[3], maskPix[3],
cursor[CURSOR_SIZENWSE] = XCreatePixmapCursor(x11_display, curPix[3], maskPix[3],
&black, &white, spot[3].x, spot[3].y);
cursor[IDC_SIZEWE] = XCreatePixmapCursor(x11_display, curPix[1], maskPix[1],
cursor[CURSOR_SIZEWE] = XCreatePixmapCursor(x11_display, curPix[1], maskPix[1],
&black, &white, spot[1].x, spot[1].y);
cursor[IDC_UPARROW] = XCreateFontCursor(x11_display, XC_sb_up_arrow);
// cursor[IDC_WAIT] = XCreateFontCursor(x11_display, XC_watch);
cursor[IDC_WAIT] = XCreatePixmapCursor(x11_display, curPix[5], maskPix[5],
cursor[CURSOR_UPARROW] = XCreateFontCursor(x11_display, XC_sb_up_arrow);
// cursor[CURSOR_WAIT] = XCreateFontCursor(x11_display, XC_watch);
cursor[CURSOR_WAIT] = XCreatePixmapCursor(x11_display, curPix[5], maskPix[5],
&black, &white, spot[5].x, spot[5].y);
if ((tmpPixmap = XCreatePixmap(x11_display,x11_window, 1, 1, 1)))
+1 -1
View File
@@ -172,7 +172,7 @@ void Xcore_drawLine(int x1, int y1, int x2, int y2, unsigned long col) {
}
}
int Xcore_drawString(int x, int y, char *msg, unsigned long col) {
int Xcore_drawString(int x, int y, const char *msg, unsigned long col) {
int w;
if (x11_font->self_drawable()) {
+43 -226
View File
@@ -28,9 +28,6 @@
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include <ctype.h>
#ifdef HAVE_SIGACTION
#include <signal.h>
@@ -67,8 +64,8 @@
#include "savedata.h"
#include "scenario.h"
#include "variable.h"
#include "dri.h"
#include "ald_manager.h"
#include "gameresource.h"
#include "filecheck.h"
#include "joystick.h"
#include "s39init.h"
@@ -77,11 +74,10 @@
#include "haveunit.h"
#endif
static char *gameResorceFile = "xsystem35.gr";
static char *gameResourceFile = "xsystem35.gr";
static void sys35_usage(boolean verbose);
static void sys35_init();
static void sys35_remove();
static boolean sys35_initGameDataResorce();
static void sys35_ParseOption(int *argc, char **argv);
static void check_profile();
@@ -90,9 +86,6 @@ static FILE *fpdebuglog;
static int debuglv = DEBUGLEVEL;
int sys_nextdebuglv;
/* game data file name */
static char *gamefname[DRIFILETYPEMAX][DRIFILEMAX];
static int audio_buffer_size = 0;
/* font name from rcfile */
@@ -127,7 +120,7 @@ static void sys35_usage(boolean verbose) {
}
puts("Usage: xsystem35 [OPTIONS]\n");
puts("OPTIONS");
puts(" -gamefile file : set game resouce file to 'file'");
puts(" -gamefile file : set game resource file to 'file'");
puts(" -no-shm : don't use MIT-SHM (use in another display)");
puts(" -devcd device : set cdrom device name to 'device'");
puts(" -devmidi device: set midi device name to 'device'");
@@ -265,220 +258,6 @@ static int check_fontdev(char *devname) {
return DEFAULT_FONT_DEVICE;
}
static void storeDataName(int type, int no, char *src) {
gamefname[type][no] = strdup(src);
}
static void storeSaveName(int no, char *src) {
char *home_dir = "";
char *path = NULL;
if (*src == '~') {
home_dir = getenv("HOME");
if (NULL == (path = malloc(strlen(home_dir) + strlen(src) + 1))) {
NOMEMERR();
}
sprintf(path, "%s%s", home_dir, src+1);
save_register_file(path, no);
src = path;
} else {
save_register_file(src, no);
}
if (no == 0) {
char *b = strrchr(src, '/');
if (b == NULL) {
SYSERROR("Illigal save filename %s\n", src);
}
*b = '\0';
save_set_path(src);
}
if (path) free(path);
}
/* ゲームのデータファイルの情報をディレクトリから作成 thanx tajiri@wizard*/
static boolean sys35_initGameDataDir(int* cnt)
{
DIR* dir;
struct dirent* d;
char s1[256], s2[256];
int dno;
int i;
getcwd(s1,255);
if(NULL == (dir= opendir(".")))
{
SYSERROR("Game Resouce File open failed\n");
}
while(NULL != (d = readdir(dir))){
char *filename = d->d_name;
int len = strlen(filename);
sprintf(s2,"%s%c%s",s1,'/',filename);
if(strcasecmp(filename,"adisk.ald")==0){
storeDataName(DRIFILE_SCO, 0, s2);
cnt[0] = max(1, cnt[0]);
} else if (strcasecmp(filename, "system39.ain") == 0) {
nact->ain.path_to_ain = strdup(filename);
}
else if(strcasecmp(filename+len-4,".ald")==0){
dno = toupper(*(filename+len-5)) - 'A';
if (dno < 0 || dno >= DRIFILEMAX) continue;
switch(*(filename+len-6)){
case 'S':
case 's':
storeDataName(DRIFILE_SCO, dno, s2);
cnt[0] = max(dno + 1, cnt[0]);
break;
case 'g':
case 'G':
storeDataName(DRIFILE_CG, dno, s2);
cnt[1] = max(dno + 1, cnt[1]);
break;
case 'W':
case 'w':
storeDataName(DRIFILE_WAVE, dno, s2);
cnt[2] = max(dno + 1, cnt[2]);
break;
case 'M':
case 'm':
storeDataName(DRIFILE_MIDI, dno, s2);
cnt[3] = max(dno + 1, cnt[3]);
break;
case 'D':
case 'd':
storeDataName(DRIFILE_DATA, dno, s2);
cnt[4] = max(dno + 1, cnt[4]);
break;
case 'R':
case 'r':
storeDataName(DRIFILE_RSC, dno, s2);
cnt[5] = max(dno + 1, cnt[5]);
break;
case 'B':
case 'b':
storeDataName(DRIFILE_BGM, dno, s2);
cnt[6] = max(dno + 1, cnt[6]);
break;
}
}
}
for(i=0;i<SAVE_MAXNUMBER;i++){
sprintf(s2,"%s/%c%s",s1,'a'+i,"sleep.asd");
storeSaveName(i, s2);
}
if(cnt[0]>0)
return TRUE;
else
return FALSE;
}
/* ゲームのデータファイルの情報を読み込む */
static boolean sys35_initGameDataResorce() {
int cnt[] = {0, 0, 0, 0, 0, 0, 0};
int linecnt = 0, dno;
FILE *fp;
char s[256];
char s1[256], s2[256];
if (NULL == (fp = fopen(gameResorceFile, "r"))) {
if(sys35_initGameDataDir(cnt)==TRUE) {
goto initdata;
}
sys35_usage(TRUE);
}
while(fgets(s, 255, fp) != NULL ) {
linecnt++;
if (s[0] == '#') continue;
s2[0] = '\0';
sscanf(s,"%s %s", s1, s2);
if (s2[0] == '\0') continue;
if (0 == strncmp(s1, "Scenario", 8)) {
dno = s1[8] - 'A';
if (dno < 0 || dno >= DRIFILEMAX) goto errexit;
storeDataName(DRIFILE_SCO, dno, s2);
cnt[0] = max(dno + 1, cnt[0]);
} else if (0 == strncmp(s1, "Graphics", 8)) {
dno = s1[8] - 'A';
if (dno < 0 || dno >= DRIFILEMAX) goto errexit;
storeDataName(DRIFILE_CG, dno, s2);
cnt[1] = max(dno + 1, cnt[1]);
} else if (0 == strncmp(s1, "Wave", 4)) {
dno = s1[4] - 'A';
if (dno < 0 || dno >= DRIFILEMAX) goto errexit;
storeDataName(DRIFILE_WAVE, dno, s2);
cnt[2] = max(dno + 1, cnt[2]);
} else if (0 == strncmp(s1, "Midi", 4)) {
dno = s1[4] - 'A';
if (dno < 0 || dno >= DRIFILEMAX) goto errexit;
storeDataName(DRIFILE_MIDI, dno, s2);
cnt[3] = max(dno + 1, cnt[3]);
} else if (0 == strncmp(s1, "Data", 4)) {
dno = s1[4] - 'A';
if (dno < 0 || dno >= DRIFILEMAX) goto errexit;
storeDataName(DRIFILE_DATA, dno, s2);
cnt[4] = max(dno + 1, cnt[4]);
} else if (0 == strncmp(s1, "Resource", 8)) {
dno = s1[8] - 'A';
if (dno < 0 || dno >= DRIFILEMAX) goto errexit;
storeDataName(DRIFILE_RSC, dno, s2);
cnt[5] = max(dno + 1, cnt[5]);
} else if (0 == strncmp(s1, "BGM", 3)) {
dno = s1[3] - 'A';
if (dno < 0 || dno >= DRIFILEMAX) goto errexit;
storeDataName(DRIFILE_BGM, dno, s2);
cnt[6] = max(dno + 1, cnt[6]);
} else if (0 == strncmp(s1, "Save", 4)) {
dno = s1[4] - 'A';
if (dno < 0 || dno >= DRIFILEMAX) goto errexit;
storeSaveName(dno, s2);
} else if (0 == strncmp(s1, "Ain", 3)) {
nact->ain.path_to_ain = strdup(s2);
} else if (0 == strncmp(s1, "WAIA", 4)) {
nact->files.wai = strdup(s2);
} else if (0 == strncmp(s1, "BGIA", 4)) {
nact->files.bgi = strdup(s2);
} else if (0 == strncmp(s1, "SACT01", 6)) {
nact->files.sact01 = strdup(s2);
} else if (0 == strncmp(s1, "Init", 4)) {
nact->files.init = strdup(s2);
} else if (0 == strncmp(s1, "ALK", 3)) {
dno = s1[4] - '0';
if (dno < 0 || dno >= 10) goto errexit;
nact->files.alk[dno] = strdup(s2);
} else {
goto errexit;
}
}
fclose(fp);
initdata:
if (cnt[0] == 0) {
SYSERROR("No Scenario data available\n");
}
if (cnt[0] > 0)
ald_init(DRIFILE_SCO, gamefname[DRIFILE_SCO], cnt[0], TRUE);
if (cnt[1] > 0)
ald_init(DRIFILE_CG, gamefname[DRIFILE_CG], cnt[1], TRUE);
if (cnt[2] > 0)
ald_init(DRIFILE_WAVE, gamefname[DRIFILE_WAVE], cnt[2], TRUE);
if (cnt[3] > 0)
ald_init(DRIFILE_MIDI, gamefname[DRIFILE_MIDI], cnt[3], TRUE);
if (cnt[4] > 0)
ald_init(DRIFILE_DATA, gamefname[DRIFILE_DATA], cnt[4], TRUE);
if (cnt[5] > 0)
ald_init(DRIFILE_RSC, gamefname[DRIFILE_RSC], cnt[5], TRUE);
if (cnt[6] > 0)
ald_init(DRIFILE_BGM, gamefname[DRIFILE_BGM], cnt[6], TRUE);
return 0;
errexit:
SYSERROR("Illigal resouce at line(%d) file<%s>\n",linecnt, gameResorceFile);
return 0;
}
static void sys35_init() {
int i;
@@ -582,7 +361,7 @@ static void sys35_ParseOption(int *argc, char **argv) {
sys35_usage(FALSE);
}
fclose(fp);
gameResorceFile = argv[i + 1];
gameResourceFile = argv[i + 1];
} else if (0 == strcmp(argv[i], "-no-shm")) {
SetNoShmMode();
} else if (0 == strcmp(argv[i], "-devcd")) {
@@ -785,6 +564,41 @@ static void init_signalhandler() {
}
#endif
static void registerGameFiles(GameResource *gr) {
if (gr->cnt[DRIFILE_SCO] == 0) {
SYSERROR("No Scenario data available\n");
}
if (gr->cnt[DRIFILE_SCO] > 0)
ald_init(DRIFILE_SCO, gr->game_fname[DRIFILE_SCO], gr->cnt[DRIFILE_SCO], TRUE);
if (gr->cnt[DRIFILE_CG] > 0)
ald_init(DRIFILE_CG, gr->game_fname[DRIFILE_CG], gr->cnt[DRIFILE_CG], TRUE);
if (gr->cnt[DRIFILE_WAVE] > 0)
ald_init(DRIFILE_WAVE, gr->game_fname[DRIFILE_WAVE], gr->cnt[DRIFILE_WAVE], TRUE);
if (gr->cnt[DRIFILE_MIDI] > 0)
ald_init(DRIFILE_MIDI, gr->game_fname[DRIFILE_MIDI], gr->cnt[DRIFILE_MIDI], TRUE);
if (gr->cnt[DRIFILE_DATA] > 0)
ald_init(DRIFILE_DATA, gr->game_fname[DRIFILE_DATA], gr->cnt[DRIFILE_DATA], TRUE);
if (gr->cnt[DRIFILE_RSC] > 0)
ald_init(DRIFILE_RSC, gr->game_fname[DRIFILE_RSC], gr->cnt[DRIFILE_RSC], TRUE);
if (gr->cnt[DRIFILE_BGM] > 0)
ald_init(DRIFILE_BGM, gr->game_fname[DRIFILE_BGM], gr->cnt[DRIFILE_BGM], TRUE);
if (gr->save_path)
save_set_path(gr->save_path);
for (int i = 0; i < SAVE_MAXNUMBER; i++) {
if (gr->save_fname[i])
save_register_file(gr->save_fname[i], i);
}
nact->ain.path_to_ain = gr->ain;
nact->files.wai = gr->wai;
nact->files.bgi = gr->bgi;
nact->files.sact01 = gr->sact01;
nact->files.init = gr->init;
for (int i = 0; i < 10; i++)
nact->files.alk[i] = gr->alk[i];
}
int main(int argc, char **argv) {
char *homedir = getenv("HOME"), *rc_name, *rc_path;
#ifdef HAVE_SIGACTION
@@ -811,7 +625,10 @@ int main(int argc, char **argv) {
}
}
#endif
sys35_initGameDataResorce();
GameResource gr;
if (!initGameResource(&gr, gameResourceFile))
sys35_usage(TRUE);
registerGameFiles(&gr);
#ifdef HAVE_SIGACTION
init_signalhandler();
-3
View File
@@ -56,9 +56,6 @@
#define DEBUG_COMMAND_YET(...)
#endif
/* 配列外参照チェック/cali異常値検出 */
#define DEBUG_CHECKALING
/* defined in cali.c */
extern int preVarPage; /* 直前にアクセスした変数のページ */
extern int preVarIndex; /* 直前にアクセスした変数のINDEX */
+5
View File
@@ -0,0 +1,5 @@
The test scenario file (`testSA.ALD`) in this directory should pass in both
xsystem35 and the original System 3.x.
To build `testSA.ALD`, install [xsys35c](https://github.com/kichikuou/xsys35c)
and run `xsys35c` command in this directory.
+61
View File
@@ -0,0 +1,61 @@
MS FILE,"array.adv":
!used:0!
!size:0!
!array:0!
!array2:0!
!index:0!
; DI should return (0, _) for an unallocated array
DI 1,used,size:
~AssertEquals used,0,__LINE__:
DC 1,10,1: ; page1 = allocate_array(11)
DC 2,0,1: ; page2 = allocate_array(1)
DC 255,65535,1: ; page255 = allocate_array(65536)
DI 1,used,size:
~AssertEquals used,1,__LINE__:
~AssertEquals size,11,__LINE__:
DI 2,used,size:
~AssertEquals used,1,__LINE__:
~AssertEquals size,1,__LINE__:
DI 255,used,size:
~AssertEquals used,1,__LINE__:
~AssertEquals size,0,__LINE__:
DS index,array,0,1: ; array maps page1[0..]
; Must be zero-initialized
~AssertEquals array[3],0,__LINE__:
!index:3!
!array:30! ; page1[3] = 30
; var[...] style access ignores the index variable
~AssertEquals array[3],30,__LINE__:
DS index,array2,1,1: ; array2 maps page1[1..]
~AssertEquals array2[2],30,__LINE__:
!index:2!
~AssertEquals array2,30,__LINE__:
DF array2,6,42: ; memset(page1+1+index, 42, 6)
~AssertEquals array[2],0,__LINE__:
~AssertEquals array[3],42,__LINE__:
~AssertEquals array[8],42,__LINE__:
~AssertEquals array[9],0,__LINE__:
!index:0!
DS index,array,0,2: ; array maps page2[0..]
!array:33!
~AssertEquals array[0],33,__LINE__:
DF array,1,66:
~AssertEquals array[0],66,__LINE__:
; Array access without DS
!D05:5!
~AssertEquals D01[4],5,__LINE__:
DF D01,5,0:
~AssertEquals D01[4],0,__LINE__:
%0:
+106
View File
@@ -0,0 +1,106 @@
MS FILE,"strvar.adv":
!len:0!
!src:0!
!dst:0!
const word str1 = 10:
const word str2 = 11:
const word str3 = 12:
MS str1,"0123456789":
ML len,str1:
~AssertEquals len,10,__LINE__:
MD str2,str1,5:
MS str3,"01234":
~AssertStrEquals str2,str3,__LINE__:
ME str2,2,str1,6,2:
MS str3,"0167":
~AssertStrEquals str2,str3,__LINE__:
MS str1,"0123456789":
ML len,str1:
~AssertEquals len,10,__LINE__:
MD str2,str1,5:
MS str3,"01234":
~AssertStrEquals str2,str3,__LINE__:
ME str2,2,str1,6,2:
MS str3,"0167":
~AssertStrEquals str2,str3,__LINE__:
MS str1,"<0x82a0>a":
MN 0,str1,D01:
~AssertEquals RND,3,__LINE__:
~AssertEquals D01,0xa082,__LINE__:
~AssertEquals D02,0x61,__LINE__: ; 'a' == "\x61"
~AssertEquals D03,0,__LINE__:
!D01:0xa182!
inc D02:
MN 1,str1,D01:
MS str2,"<0x82a1>b":
~AssertStrEquals str1,str2,__LINE__:
MS str1,"あいうabc123":
MS str2,"c":
MF D01,str1,str2,0:
~AssertEquals RND,0,__LINE__:
~AssertEquals D01,5,__LINE__:
MF RND,str1,str2,5:
~AssertEquals RND,0,__LINE__:
~AssertEquals D01,5,__LINE__:
MF RND,str1,str2,6:
~AssertEquals RND,255,__LINE__:
MH str1,0,0:
MS str2,"":
~AssertStrEquals str1,str2,__LINE__:
MH str1,0,12345:
MS str2,"12345":
~AssertStrEquals str1,str2,__LINE__:
MH str1,3,12345:
MS str2,"345":
~AssertStrEquals str1,str2,__LINE__:
MH str1,6,12345:
MS str2," 12345":
~AssertStrEquals str1,str2,__LINE__:
MHH str1,0,0:
MS str2,"0":
~AssertStrEquals str1,str2,__LINE__:
MHH str1,0,12345:
MS str2,"12345":
~AssertStrEquals str1,str2,__LINE__:
MHH str1,3,12345:
MS str2,"345":
~AssertStrEquals str1,str2,__LINE__:
MHH str1,6,12345:
MS str2," 12345":
~AssertStrEquals str1,str2,__LINE__:
MS str1,"123あいう":
~MPtoString str2,str1,5:
MS str3,"123あい":
~AssertStrEquals str2,str3,__LINE__:
~MPtoString str2,str1,8:
MS str3,"123あいう  ":
~AssertStrEquals str2,str3,__LINE__:
MS str2,"0123456789":
MM str1,str2:
~AssertStrEquals str1,str2,__LINE__:
<D01,20,500,1,10:
MA str1,str2:
ML len,str1:
~AssertEquals len,D01,__LINE__:
>
%0:
**MPtoString dst,src,len:
MG 100,0:
MG 1,dst:
MG 4,0:
MG 0,1:
MP src,len:
MG 0,0:
MG 100,1:
%0:
+18
View File
@@ -0,0 +1,18 @@
!RND:0!
!D01:0!!D02:0!!D03:0!!D04:0!!D05:0!!D06:0!!D07:0!!D08:0!!D09:0!!D10:0!
!D11:0!!D12:0!!D13:0!!D14:0!!D15:0!!D16:0!!D17:0!!D18:0!!D19:0!!D20:0!
MZ0,50,100,0:
B3,1,8,8,624,464,0:
B4,1,0,0,0,1,0:
ZH 2:
!tests_passed:0!
!tests_failed:0!
%#array.adv:
%#strvar.adv:
HH0,tests_passed: ' tests passed' R
HH0,tests_failed: ' tests failed' R
{tests_failed: A}
ZZ0,0:
+5
View File
@@ -0,0 +1,5 @@
#SYSTEM35
test.adv
util.adv
array.adv
strvar.adv
BIN
View File
Binary file not shown.
+29
View File
@@ -0,0 +1,29 @@
const word FILE = 1:
!actual:0!
!expected:0!
!line:0!
**AssertEquals actual,expected,line:
{expected = actual:
inc tests_passed:
%0:
}
inc tests_failed:
'[FAIL] ' X FILE: ':' HH0,line:
' expected: ' HH0,expected:
' actual: ' HH0,actual:
R
%0:
**AssertStrEquals actual,expected,line:
MC actual,expected:
{RND = 1:
inc tests_passed:
%0:
}
inc tests_failed:
'[FAIL] ' X FILE: ':' HH0,line:
' expected: "' X expected: '"'
' actual: "' X actual: '"'
R
%0:
+3
View File
@@ -0,0 +1,3 @@
ald_basename = test
sys_ver = 3.8
hed = test.hed