mirror of
https://github.com/nunuhara/xsystem4.git
synced 2026-10-04 04:48:09 +03:00
Reorganize project file structure
- Create separate directories for source and header files. - Build code shared between xsystem4 and aindump as a static library. - Create header dirs gfx/ system4/ and vm/ - Make CG.c/h usable without a running VM
This commit is contained in:
+2
-1
@@ -1,2 +1,3 @@
|
||||
build
|
||||
*.ain
|
||||
*.ain
|
||||
.dir-locals.el
|
||||
@@ -4,7 +4,9 @@ xsystem4
|
||||
xsystem4 is an implementation of AliceSoft's System 4 game engine for unix-like
|
||||
operating systems.
|
||||
|
||||
NOTE: This is a work in progress. Very little is implemented so far.
|
||||
NOTE: This is a work in progress. Some simple ADV games run more or less okay,
|
||||
but most games are not fully working or have game-breaking bug when run
|
||||
with xsystem4.
|
||||
|
||||
Building
|
||||
--------
|
||||
@@ -18,7 +20,10 @@ xsystem4 uses the meson build system.
|
||||
Running
|
||||
-------
|
||||
|
||||
You will need to create an AIN file using the System 4 SDK compiler. Then simply
|
||||
pass it to the system4 executable.
|
||||
You can run a game by passing the path to its "System40.ini" to the xsystem4
|
||||
executable.
|
||||
|
||||
build/system4 ???.ain
|
||||
build/src/xsystem4 /path/to/System40.ini
|
||||
|
||||
For now, xsystem4 needs to be run in the top-level project directory (i.e. the
|
||||
directory that contains this README file). This will change in the future.
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <stdint.h>
|
||||
#include <SDL.h>
|
||||
#include <GL/glew.h>
|
||||
#include "graphics.h"
|
||||
#include "gfx/types.h"
|
||||
|
||||
struct cg;
|
||||
struct text_metrics;
|
||||
@@ -1,4 +1,4 @@
|
||||
/* gfx_private.h SDL/OpenGL only private data
|
||||
/* gfx/private.h SDL/OpenGL only private data
|
||||
*
|
||||
* Copyright (C) 2019 Nunuhara Cabbage <nunuhara@haniwa.technology>
|
||||
* Copyright (C) 2000- Fumihiko Murata <fmurata@p1.tcnet.ne.jp>
|
||||
@@ -21,8 +21,8 @@
|
||||
#include <SDL.h>
|
||||
#include <GL/glew.h>
|
||||
#include "queue.h"
|
||||
#include "graphics.h"
|
||||
#include "gfx_core.h"
|
||||
#include "gfx/gfx.h"
|
||||
#include "gfx/types.h"
|
||||
|
||||
struct string;
|
||||
union vm_value;
|
||||
@@ -21,9 +21,8 @@
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "vm_string.h"
|
||||
|
||||
struct ain;
|
||||
struct string;
|
||||
union vm_value;
|
||||
|
||||
enum ain_error {
|
||||
AIN_SUCCESS,
|
||||
@@ -153,8 +152,6 @@ struct ain_hll_argument {
|
||||
int32_t data_type;
|
||||
};
|
||||
|
||||
union vm_value;
|
||||
|
||||
struct ain_hll_function {
|
||||
char *name;
|
||||
union vm_value (*fun)(union vm_value *args);
|
||||
@@ -231,6 +228,5 @@ const char *ain_strerror(int error);
|
||||
const char *ain_strtype(struct ain *ain, enum ain_data_type type, int struct_type);
|
||||
struct ain *ain_open(const char *path, int *error);
|
||||
void ain_free(struct ain *ain);
|
||||
void vm_execute_ain(struct ain *program);
|
||||
|
||||
#endif /* SYSTEM4_AIN_H */
|
||||
@@ -22,6 +22,8 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct ald_archive;
|
||||
|
||||
/*
|
||||
* Available CG formats
|
||||
*/
|
||||
@@ -51,9 +53,8 @@ struct cg {
|
||||
void *pixels;
|
||||
};
|
||||
|
||||
bool cg_exists(int no);
|
||||
bool cg_get_metrics(int no, struct cg_metrics *dst);
|
||||
struct cg *cg_load(int no);
|
||||
bool cg_get_metrics(struct ald_archive *ar, int no, struct cg_metrics *dst);
|
||||
struct cg *cg_load(struct ald_archive *ar, int no);
|
||||
void cg_free(struct cg *cg);
|
||||
|
||||
#endif /* SYSTEM4_CG_H */
|
||||
@@ -28,8 +28,9 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <SDL.h>
|
||||
#include "cg.h"
|
||||
|
||||
struct cg;
|
||||
struct cg_metrics;
|
||||
|
||||
struct qnt_header {
|
||||
int hdr_size; // header size
|
||||
@@ -46,6 +46,7 @@ struct string *string_format(struct string *fmt, union vm_value arg);
|
||||
|
||||
// mutators
|
||||
void string_append(struct string **a, const struct string *b);
|
||||
void string_append_cstr(struct string **a, const char *b, size_t b_size);
|
||||
void string_push_back(struct string **s, int c);
|
||||
void string_pop_back(struct string **s);
|
||||
void string_erase(struct string **s, int index);
|
||||
@@ -55,7 +56,7 @@ int string_find(const struct string *haystack, const struct string *needle);
|
||||
|
||||
// characters
|
||||
int string_get_char(const struct string *str, int i);
|
||||
void string_set_char(struct string **_s, int i, unsigned int c);
|
||||
void string_set_char(struct string **s, int i, unsigned int c);
|
||||
|
||||
// C strings
|
||||
int int_to_cstr(char *buf, size_t size, int v, int figures, bool zero_pad, bool zenkaku);
|
||||
@@ -107,6 +107,7 @@ int vm_string_ref(struct string *s);
|
||||
int vm_copy_page(struct page *page);
|
||||
union vm_value vm_copy(union vm_value v, enum ain_data_type type);
|
||||
|
||||
void vm_execute_ain(struct ain *program);
|
||||
void vm_call(int fno, int struct_page);
|
||||
int vm_time(void);
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "ain.h"
|
||||
#include "system4/ain.h"
|
||||
#include "vm.h"
|
||||
|
||||
struct ain_variable;
|
||||
+5
-54
@@ -1,50 +1,7 @@
|
||||
project('system4', 'c', default_options : ['c_std=c11'])
|
||||
project('system4', 'c',
|
||||
default_options : ['c_std=c11'])
|
||||
add_project_arguments('-D_DEFAULT_SOURCE', language : 'c')
|
||||
|
||||
system4 = ['ain.c',
|
||||
'instructions.c',
|
||||
'string.c',
|
||||
'system.c',
|
||||
'utfsjis.c',
|
||||
]
|
||||
|
||||
xsystem4 = ['ald.c',
|
||||
'audio.c',
|
||||
'cJSON.c',
|
||||
'cg.c',
|
||||
'draw.c',
|
||||
'effect.c',
|
||||
'file.c',
|
||||
'heap.c',
|
||||
'ini.c',
|
||||
'input.c',
|
||||
'page.c',
|
||||
'qnt.c',
|
||||
'resume.c',
|
||||
'sact_graphics.c',
|
||||
'savedata.c',
|
||||
'system4.c',
|
||||
'text.c',
|
||||
'video.c',
|
||||
'vm.c',
|
||||
|
||||
'hll/ACXLoader.c',
|
||||
'hll/AliceLogo.c',
|
||||
'hll/AliceLogo2.c',
|
||||
'hll/AliceLogo3.c',
|
||||
'hll/Confirm2.c',
|
||||
'hll/DrawGraph.c',
|
||||
'hll/DrawPluginManager.c',
|
||||
'hll/File.c',
|
||||
'hll/Math.c',
|
||||
'hll/MsgLogManager.c',
|
||||
'hll/MsgSkip.c',
|
||||
'hll/OutputLog.c',
|
||||
'hll/PlayMovie.c',
|
||||
'hll/SACT2.c',
|
||||
'hll/SystemServiceEx.c',
|
||||
]
|
||||
|
||||
zlib = dependency('zlib')
|
||||
libm = meson.get_compiler('c').find_library('m', required: false)
|
||||
sdl2 = dependency('sdl2')
|
||||
@@ -52,14 +9,8 @@ sdl2ttf = dependency('SDL2_ttf')
|
||||
sdl2mixer = dependency('SDL2_mixer')
|
||||
gl = dependency('GL')
|
||||
glew = dependency('glew')
|
||||
xsystem4_deps = [libm, zlib, sdl2, sdl2ttf, sdl2mixer, gl, glew]
|
||||
|
||||
chibi = dependency('chibi-scheme', required : get_option('debugger'))
|
||||
if chibi.found()
|
||||
xsystem4_deps += chibi
|
||||
xsystem4 += 'debugger.c'
|
||||
add_project_arguments('-DDEBUGGER_ENABLED', language : 'c')
|
||||
endif
|
||||
|
||||
executable('system4', xsystem4 + system4, dependencies: xsystem4_deps, c_args : ['-Wno-unused-parameter'])
|
||||
executable('aindump', ['aindump.c'] + system4, dependencies: [libm, zlib])
|
||||
incdir = include_directories('include')
|
||||
|
||||
subdir('src')
|
||||
|
||||
+4
-4
@@ -24,11 +24,11 @@
|
||||
#include <string.h>
|
||||
#include <zlib.h>
|
||||
|
||||
#include "system4.h"
|
||||
#include "ain.h"
|
||||
#include "little_endian.h"
|
||||
#include "instructions.h"
|
||||
#include "vm_string.h"
|
||||
#include "system4.h"
|
||||
#include "system4/ain.h"
|
||||
#include "system4/instructions.h"
|
||||
#include "system4/string.h"
|
||||
|
||||
static const char *errtab[AIN_MAX_ERROR] = {
|
||||
[AIN_SUCCESS] = "Success",
|
||||
@@ -19,11 +19,12 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include "system4.h"
|
||||
#include "ain.h"
|
||||
#include "instructions.h"
|
||||
#include "little_endian.h"
|
||||
#include "utfsjis.h"
|
||||
#include "system4.h"
|
||||
#include "system4/ain.h"
|
||||
#include "system4/instructions.h"
|
||||
#include "system4/string.h"
|
||||
#include "system4/utfsjis.h"
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
@@ -50,6 +51,11 @@ static void print_sjis(const char *s)
|
||||
free(u);
|
||||
}
|
||||
|
||||
static void ain_dump_version(struct ain *ain)
|
||||
{
|
||||
printf("AIN VERSION %d\n", ain->version);
|
||||
}
|
||||
|
||||
static void ain_dump_code(struct ain *ain)
|
||||
{
|
||||
for (size_t i = 0; i < ain->code_size;) {
|
||||
@@ -141,7 +147,7 @@ static void ain_dump_messages(struct ain *ain)
|
||||
{
|
||||
for (int i = 0; i < ain->nr_messages; i++) {
|
||||
print_sjis(ain->messages[i]->text);
|
||||
printf("\n---\n");
|
||||
//printf("\n---\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +182,7 @@ static void ain_dump_strings(struct ain *ain)
|
||||
{
|
||||
for (int i = 0; i < ain->nr_strings; i++) {
|
||||
print_sjis(ain->strings[i]->text);
|
||||
printf("\n---\n");
|
||||
//printf("\n---\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,6 +225,7 @@ static void ain_dump_enums(struct ain *ain)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
bool dump_version = false;
|
||||
bool dump_code = false;
|
||||
bool dump_functions = false;
|
||||
bool dump_globals = false;
|
||||
@@ -236,6 +243,7 @@ int main(int argc, char *argv[])
|
||||
while (1) {
|
||||
static struct option long_options[] = {
|
||||
{ "help", no_argument, 0, 'h' },
|
||||
{ "ain-version", no_argument, 0, 'a' },
|
||||
{ "code", no_argument, 0, 'c' },
|
||||
{ "functions", no_argument, 0, 'f' },
|
||||
{ "globals", no_argument, 0, 'g' },
|
||||
@@ -251,7 +259,7 @@ int main(int argc, char *argv[])
|
||||
int option_index = 0;
|
||||
int c;
|
||||
|
||||
c = getopt_long(argc, argv, "hcfgomlse", long_options, &option_index);
|
||||
c = getopt_long(argc, argv, "hacfgomlse", long_options, &option_index);
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
@@ -259,6 +267,9 @@ int main(int argc, char *argv[])
|
||||
case 'h':
|
||||
usage();
|
||||
return 0;
|
||||
case 'a':
|
||||
dump_version = true;
|
||||
break;
|
||||
case 'c':
|
||||
dump_code = true;
|
||||
break;
|
||||
@@ -308,6 +319,8 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (dump_version)
|
||||
ain_dump_version(ain);
|
||||
if (dump_structures)
|
||||
ain_dump_structures(ain);
|
||||
if (dump_functypes)
|
||||
+1
-1
@@ -26,7 +26,7 @@
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include "little_endian.h"
|
||||
#include "ald.h"
|
||||
#include "system4/ald.h"
|
||||
|
||||
static const char *errtab[ALD_MAX_ERROR] = {
|
||||
[ALD_SUCCESS] = "Success",
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <SDL_mixer.h>
|
||||
#include "ald.h"
|
||||
#include "audio.h"
|
||||
#include "system4.h"
|
||||
#include "system4/ald.h"
|
||||
|
||||
#define AUDIO_SLOT_ALLOC_STEP 256
|
||||
|
||||
+10
-22
@@ -17,17 +17,10 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <SDL.h>
|
||||
#include "system4.h"
|
||||
#include "ald.h"
|
||||
#include "cg.h"
|
||||
#include "qnt.h"
|
||||
#include "graphics.h"
|
||||
|
||||
bool cg_exists(int no)
|
||||
{
|
||||
return ald[ALDFILE_CG] && ald_data_exists(ald[ALDFILE_CG], no);
|
||||
}
|
||||
#include "system4/ald.h"
|
||||
#include "system4/cg.h"
|
||||
#include "system4/qnt.h"
|
||||
|
||||
/*
|
||||
* Identify cg format
|
||||
@@ -42,11 +35,11 @@ static enum cg_type check_cgformat(uint8_t *data)
|
||||
return ALCG_UNKNOWN;
|
||||
}
|
||||
|
||||
bool cg_get_metrics(int no, struct cg_metrics *dst)
|
||||
bool cg_get_metrics(struct ald_archive *ar, int no, struct cg_metrics *dst)
|
||||
{
|
||||
struct archive_data *dfile;
|
||||
|
||||
if (!(dfile = ald_get(ald[ALDFILE_CG], no)))
|
||||
if (!(dfile = ald_get(ar, no)))
|
||||
return false;
|
||||
|
||||
switch (check_cgformat(dfile->data)) {
|
||||
@@ -62,20 +55,15 @@ bool cg_get_metrics(int no, struct cg_metrics *dst)
|
||||
return true;
|
||||
}
|
||||
|
||||
static void _cg_free(struct cg *cg)
|
||||
{
|
||||
if (!cg)
|
||||
return;
|
||||
free(cg->pixels);
|
||||
}
|
||||
|
||||
/*
|
||||
* Free CG data
|
||||
* cg: object to free
|
||||
*/
|
||||
void cg_free(struct cg *cg)
|
||||
{
|
||||
_cg_free(cg);
|
||||
if (!cg)
|
||||
return;
|
||||
free(cg->pixels);
|
||||
free(cg);
|
||||
}
|
||||
|
||||
@@ -84,13 +72,13 @@ void cg_free(struct cg *cg)
|
||||
* no: file no ( >= 0)
|
||||
* return: cg object(extracted)
|
||||
*/
|
||||
struct cg *cg_load(int no)
|
||||
struct cg *cg_load(struct ald_archive *ar, int no)
|
||||
{
|
||||
struct cg *cg;
|
||||
struct archive_data *dfile;
|
||||
int type;
|
||||
|
||||
if (!(dfile = ald_get(ald[ALDFILE_CG], no))) {
|
||||
if (!(dfile = ald_get(ar, no))) {
|
||||
WARNING("Failed to load CG %d", no);
|
||||
return NULL;
|
||||
}
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
#include <chibi/eval.h>
|
||||
|
||||
#include "ain.h"
|
||||
#include "system4/ain.h"
|
||||
|
||||
#include "page.h"
|
||||
#include "vm/page.h"
|
||||
|
||||
#include "vm.h"
|
||||
/*
|
||||
@@ -13,8 +13,8 @@
|
||||
;; You should have received a copy of the GNU General Public License
|
||||
;; along with this program; if not, see <http://gnu.org/licenses/>.
|
||||
|
||||
(c-include "ain.h")
|
||||
(c-include "page.h")
|
||||
(c-include "system4/ain.h")
|
||||
(c-include "vm/page.h")
|
||||
(c-include "vm.h")
|
||||
|
||||
(define-c-const int (type/void AIN_VOID))
|
||||
@@ -17,10 +17,11 @@
|
||||
#include <stdio.h>
|
||||
#include <chibi/eval.h>
|
||||
|
||||
#include "heap.h"
|
||||
#include "page.h"
|
||||
#include "utfsjis.h"
|
||||
#include "system4/string.h"
|
||||
#include "system4/utfsjis.h"
|
||||
#include "vm.h"
|
||||
#include "vm/heap.h"
|
||||
#include "vm/page.h"
|
||||
|
||||
struct variable {
|
||||
enum ain_data_type data_type;
|
||||
+2
-2
@@ -17,8 +17,8 @@
|
||||
#include <math.h>
|
||||
#include <SDL.h>
|
||||
#include <GL/glew.h>
|
||||
#include "gfx_core.h"
|
||||
#include "gfx_private.h"
|
||||
#include "gfx/gfx.h"
|
||||
#include "gfx/private.h"
|
||||
#include "system4.h"
|
||||
|
||||
#ifndef M_PI
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
#include <SDL.h>
|
||||
#include "effect.h"
|
||||
#include "gfx_core.h"
|
||||
#include "gfx/gfx.h"
|
||||
#include "sact.h"
|
||||
#include "system4.h"
|
||||
|
||||
+160
@@ -0,0 +1,160 @@
|
||||
/* Copyright (C) 2019 Nunuhara Cabbage <nunuhara@haniwa.technology>
|
||||
*
|
||||
* 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, see <http://gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include "system4.h"
|
||||
#include "system4/string.h"
|
||||
#include "vm.h"
|
||||
#include "vm/heap.h"
|
||||
|
||||
#define DIGIT_MAX 512
|
||||
|
||||
enum fmt_type {
|
||||
FMT_VOID,
|
||||
FMT_INT,
|
||||
FMT_FLOAT,
|
||||
FMT_STRING,
|
||||
FMT_CHAR,
|
||||
FMT_BOOL
|
||||
};
|
||||
|
||||
struct fmt_spec {
|
||||
enum fmt_type type;
|
||||
int precision;
|
||||
int padding;
|
||||
bool zero_pad;
|
||||
bool zenkaku;
|
||||
};
|
||||
|
||||
static int read_number(const char **_fmt)
|
||||
{
|
||||
int n = 0;
|
||||
const char *fmt = *_fmt;
|
||||
while (*fmt && *fmt >= '0' && *fmt <= '9') {
|
||||
n *= 10;
|
||||
n += *fmt - '0';
|
||||
fmt++;
|
||||
}
|
||||
*_fmt = fmt;
|
||||
return n;
|
||||
}
|
||||
|
||||
static void parse_fmt_spec(const char **_fmt, struct fmt_spec *spec)
|
||||
{
|
||||
const char *fmt = *_fmt;
|
||||
memset(spec, 0, sizeof(struct fmt_spec));
|
||||
spec->precision = 6;
|
||||
while (*fmt) {
|
||||
switch (*fmt) {
|
||||
case 'd':
|
||||
spec->type = FMT_INT;
|
||||
goto end;
|
||||
case 'D':
|
||||
spec->type = FMT_INT;
|
||||
spec->zenkaku = true;
|
||||
goto end;
|
||||
case 'f':
|
||||
spec->type = FMT_FLOAT;
|
||||
goto end;
|
||||
case 'F':
|
||||
spec->type = FMT_FLOAT;
|
||||
spec->zenkaku = true;
|
||||
goto end;
|
||||
case 's':
|
||||
spec->type = FMT_STRING;
|
||||
goto end;
|
||||
case 'c':
|
||||
spec->type = FMT_CHAR;
|
||||
goto end;
|
||||
case 'b':
|
||||
spec->type = FMT_BOOL;
|
||||
goto end;
|
||||
case '0':
|
||||
spec->zero_pad = true;
|
||||
fmt++;
|
||||
break;
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
spec->padding = read_number(&fmt);
|
||||
break;
|
||||
case '.':
|
||||
fmt++;
|
||||
spec->precision = read_number(&fmt);
|
||||
break;
|
||||
default:
|
||||
goto warn;
|
||||
}
|
||||
}
|
||||
warn:
|
||||
WARNING("Invalid format specifier: %s", *_fmt);
|
||||
end:
|
||||
*_fmt = ++fmt;
|
||||
}
|
||||
|
||||
static void append_fmt(struct string **s, struct fmt_spec *spec, union vm_value arg)
|
||||
{
|
||||
int len;
|
||||
char buf[DIGIT_MAX] = { [DIGIT_MAX-1] = '\0' };
|
||||
switch (spec->type) {
|
||||
case FMT_VOID:
|
||||
return;
|
||||
case FMT_INT:
|
||||
len = int_to_cstr(buf, DIGIT_MAX, arg.i, spec->padding, spec->zero_pad, spec->zenkaku);
|
||||
string_append_cstr(s, buf, len);
|
||||
break;
|
||||
case FMT_FLOAT:
|
||||
len = float_to_cstr(buf, DIGIT_MAX, arg.f, spec->padding, spec->zero_pad, spec->precision, spec->zenkaku);
|
||||
string_append_cstr(s, buf, len);
|
||||
break;
|
||||
case FMT_STRING:
|
||||
string_append(s, heap[arg.i].s);
|
||||
break;
|
||||
case FMT_CHAR:
|
||||
string_push_back(s, arg.i);
|
||||
break;
|
||||
case FMT_BOOL:
|
||||
if (arg.i)
|
||||
string_append_cstr(s, "true", 4);
|
||||
else
|
||||
string_append_cstr(s, "false", 5);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
struct string *string_format(struct string *fmt, union vm_value arg)
|
||||
{
|
||||
struct string *out = string_ref(&EMPTY_STRING);
|
||||
for (const char *s = fmt->text; *s; s++) {
|
||||
if (*s == '%') {
|
||||
struct fmt_spec spec;
|
||||
string_append_cstr(&out, fmt->text, s - fmt->text);
|
||||
s++;
|
||||
parse_fmt_spec(&s, &spec);
|
||||
append_fmt(&out, &spec, arg);
|
||||
string_append_cstr(&out, s, strlen(s));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
+3
-2
@@ -15,9 +15,10 @@
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "page.h"
|
||||
#include "heap.h"
|
||||
#include "system4/string.h"
|
||||
#include "vm.h"
|
||||
#include "vm/heap.h"
|
||||
#include "vm/page.h"
|
||||
|
||||
#define INITIAL_HEAP_SIZE 4096
|
||||
#define HEAP_ALLOC_STEP 4096
|
||||
@@ -18,7 +18,8 @@
|
||||
#include <string.h>
|
||||
#include <zlib.h>
|
||||
#include "hll.h"
|
||||
#include "../little_endian.h"
|
||||
#include "little_endian.h"
|
||||
#include "system4/string.h"
|
||||
|
||||
struct acx_file {
|
||||
int compressed_size;
|
||||
@@ -15,8 +15,9 @@
|
||||
*/
|
||||
|
||||
#include "hll.h"
|
||||
#include "../sact.h"
|
||||
#include "../graphics.h"
|
||||
#include "sact.h"
|
||||
#include "gfx/types.h"
|
||||
#include "system4/string.h"
|
||||
|
||||
#define TEX(sp_no) sact_get_texture(sp_no)
|
||||
|
||||
@@ -16,14 +16,16 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/stat.h>
|
||||
#include "hll.h"
|
||||
#include "../file.h"
|
||||
#include "../heap.h"
|
||||
#include "../savedata.h"
|
||||
#include "../system4.h"
|
||||
#include "file.h"
|
||||
#include "savedata.h"
|
||||
#include "system4.h"
|
||||
#include "system4/string.h"
|
||||
#include "vm/heap.h"
|
||||
|
||||
static FILE *current_file = NULL;
|
||||
static char *file_contents = NULL;
|
||||
@@ -21,7 +21,6 @@
|
||||
#define M_PI (3.14159265358979323846)
|
||||
#endif
|
||||
|
||||
#include "../system4.h"
|
||||
#include "hll.h"
|
||||
|
||||
static inline float deg2rad(float deg)
|
||||
@@ -16,7 +16,8 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include "hll.h"
|
||||
#include "../utfsjis.h"
|
||||
#include "system4/string.h"
|
||||
#include "system4/utfsjis.h"
|
||||
|
||||
hll_warn_unimplemented(OutputLog, Create, 0)
|
||||
|
||||
@@ -17,14 +17,15 @@
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
#include "hll.h"
|
||||
#include "../audio.h"
|
||||
#include "../cg.h"
|
||||
#include "../input.h"
|
||||
#include "../queue.h"
|
||||
#include "../gfx_core.h"
|
||||
#include "../sact.h"
|
||||
#include "../system4.h"
|
||||
#include "../vm.h"
|
||||
#include "audio.h"
|
||||
#include "input.h"
|
||||
#include "queue.h"
|
||||
#include "gfx/gfx.h"
|
||||
#include "sact.h"
|
||||
#include "system4.h"
|
||||
#include "system4/ald.h"
|
||||
#include "system4/cg.h"
|
||||
#include "system4/string.h"
|
||||
|
||||
// int Init(imain_system pIMainSystem, int nCGCacheSize)
|
||||
hll_defun_inline(Init, sact_Init());
|
||||
@@ -413,7 +414,10 @@ hll_defun_inline(Key_IsDown, (handle_events(), key_is_down(a[0].i)));
|
||||
// int Timer_Get(void)
|
||||
hll_defun_inline(Timer_Get, vm_time());
|
||||
// int CG_IsExist(int nCG)
|
||||
hll_defun_inline(CG_IsExist, cg_exists(a[0].i - 1));
|
||||
hll_defun(CG_IsExist, args)
|
||||
{
|
||||
hll_return(ald[ALDFILE_CG] && ald_data_exists(ald[ALDFILE_CG], args[0].i - 1));
|
||||
}
|
||||
// int CG_GetMetrics(int nCG, ref struct cm)
|
||||
hll_defun_inline(CG_GetMetrics, sact_CG_GetMetrics(a[0].i - 1, heap[a[1].i].page->values));
|
||||
// int CSV_Load(string pIStringFileName)
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
#include "hll.h"
|
||||
#include "../gfx_core.h"
|
||||
#include "gfx/gfx.h"
|
||||
|
||||
// int GetUpdateResult()
|
||||
hll_unimplemented(SystemServiceEx, GetUpdateResult);
|
||||
@@ -21,10 +21,10 @@
|
||||
* DSL for implementing libraries.
|
||||
*/
|
||||
|
||||
#include "../vm.h"
|
||||
#include "../heap.h"
|
||||
#include "../page.h"
|
||||
#include "../system4.h"
|
||||
#include "vm.h"
|
||||
#include "vm/heap.h"
|
||||
#include "vm/page.h"
|
||||
#include "system4.h"
|
||||
|
||||
#define hll_defun(fname, args) \
|
||||
static union vm_value _hllfun_ ## fname(possibly_unused union vm_value *args); \
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
#include <SDL.h>
|
||||
#include "system4.h"
|
||||
#include "gfx_private.h"
|
||||
#include "gfx/private.h"
|
||||
#include "input.h"
|
||||
#include "vm.h"
|
||||
|
||||
@@ -95,6 +95,8 @@ void handle_events(void)
|
||||
}
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
if (e.key.keysym.scancode == SDL_SCANCODE_F9)
|
||||
vm_stack_trace();
|
||||
key_event(&e.key, true);
|
||||
break;
|
||||
case SDL_KEYUP:
|
||||
@@ -19,7 +19,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "system4.h"
|
||||
#include "instructions.h"
|
||||
#include "system4/instructions.h"
|
||||
|
||||
// JMP = instruction that modifies the instruction pointer
|
||||
// OP = everything else
|
||||
@@ -0,0 +1,69 @@
|
||||
# sources for libsys4.a
|
||||
system4 = ['ain.c',
|
||||
'ald.c',
|
||||
'cg.c',
|
||||
'instructions.c',
|
||||
'qnt.c',
|
||||
'string.c',
|
||||
'system.c',
|
||||
'utfsjis.c',
|
||||
]
|
||||
|
||||
# sources for xsystem4
|
||||
xsystem4 = ['audio.c',
|
||||
'cJSON.c',
|
||||
'draw.c',
|
||||
'effect.c',
|
||||
'file.c',
|
||||
'format.c',
|
||||
'heap.c',
|
||||
'ini.c',
|
||||
'input.c',
|
||||
'page.c',
|
||||
'resume.c',
|
||||
'sact_graphics.c',
|
||||
'savedata.c',
|
||||
'system4.c',
|
||||
'text.c',
|
||||
'video.c',
|
||||
'vm.c',
|
||||
|
||||
'hll/ACXLoader.c',
|
||||
'hll/AliceLogo.c',
|
||||
'hll/AliceLogo2.c',
|
||||
'hll/AliceLogo3.c',
|
||||
'hll/Confirm2.c',
|
||||
'hll/DrawGraph.c',
|
||||
'hll/DrawPluginManager.c',
|
||||
'hll/File.c',
|
||||
'hll/Math.c',
|
||||
'hll/MsgLogManager.c',
|
||||
'hll/MsgSkip.c',
|
||||
'hll/OutputLog.c',
|
||||
'hll/PlayMovie.c',
|
||||
'hll/SACT2.c',
|
||||
'hll/SystemServiceEx.c',
|
||||
]
|
||||
|
||||
xsystem4_deps = [libm, zlib, sdl2, sdl2ttf, sdl2mixer, gl, glew]
|
||||
if chibi.found()
|
||||
xsystem4_deps += chibi
|
||||
xsystem4 += 'debugger.c'
|
||||
add_project_arguments('-DDEBUGGER_ENABLED', language : 'c')
|
||||
endif
|
||||
|
||||
libsys4 = static_library('sys4', system4,
|
||||
dependencies : [libm, zlib],
|
||||
include_directories : incdir)
|
||||
|
||||
executable('xsystem4', xsystem4,
|
||||
dependencies : xsystem4_deps,
|
||||
c_args : ['-Wno-unused-parameter'],
|
||||
include_directories : incdir,
|
||||
link_with : libsys4)
|
||||
|
||||
executable('aindump', ['aindump.c'],
|
||||
dependencies : [libm, zlib],
|
||||
include_directories : incdir,
|
||||
link_with : libsys4)
|
||||
|
||||
+4
-4
@@ -16,11 +16,11 @@
|
||||
|
||||
#include <string.h>
|
||||
#include "system4.h"
|
||||
#include "ain.h"
|
||||
#include "heap.h"
|
||||
#include "page.h"
|
||||
#include "system4/ain.h"
|
||||
#include "system4/string.h"
|
||||
#include "vm.h"
|
||||
#include "vm_string.h"
|
||||
#include "vm/heap.h"
|
||||
#include "vm/page.h"
|
||||
|
||||
#define NR_CACHES 8
|
||||
#define CACHE_SIZE 64
|
||||
+3
-5
@@ -32,14 +32,12 @@
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <zlib.h>
|
||||
#include <SDL.h>
|
||||
|
||||
#include "little_endian.h"
|
||||
#include "cg.h"
|
||||
#include "qnt.h"
|
||||
#include "system4.h"
|
||||
#include "gfx_core.h"
|
||||
#include "system4/cg.h"
|
||||
#include "system4/qnt.h"
|
||||
|
||||
/*
|
||||
zlib の展開バッファで、幅×高さ×3に、さらにどれくらい余裕をとるか
|
||||
@@ -22,10 +22,11 @@
|
||||
#include <errno.h>
|
||||
#include "cJSON.h"
|
||||
#include "file.h"
|
||||
#include "heap.h"
|
||||
#include "page.h"
|
||||
#include "savedata.h"
|
||||
#include "system4/string.h"
|
||||
#include "vm.h"
|
||||
#include "vm/heap.h"
|
||||
#include "vm/page.h"
|
||||
|
||||
/*
|
||||
* Save/load VM images as JSON.
|
||||
@@ -14,15 +14,16 @@
|
||||
* along with this program; if not, see <http://gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "system4.h"
|
||||
#include "sact.h"
|
||||
#include "audio.h"
|
||||
#include "cg.h"
|
||||
#include "input.h"
|
||||
#include "gfx_core.h"
|
||||
#include "gfx/gfx.h"
|
||||
#include "sact.h"
|
||||
#include "system4.h"
|
||||
#include "system4/ald.h"
|
||||
#include "system4/cg.h"
|
||||
#include "system4/string.h"
|
||||
#include "system4/utfsjis.h"
|
||||
#include "vm.h"
|
||||
#include "vm_string.h"
|
||||
#include "utfsjis.h"
|
||||
|
||||
static struct sact_sprite *create_sprite(int sp_no, int width, int height, int r, int g, int b, int a);
|
||||
|
||||
@@ -124,7 +125,7 @@ int sact_SetWP(int cg_no)
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct cg *cg = cg_load(cg_no - 1);
|
||||
struct cg *cg = cg_load(ald[ALDFILE_CG], cg_no - 1);
|
||||
if (!cg)
|
||||
return 0;
|
||||
|
||||
@@ -210,7 +211,7 @@ int sact_SP_SetCG(int sp_no, int cg_no)
|
||||
WARNING("Failed to create sprite");
|
||||
return 0;
|
||||
}
|
||||
struct cg *cg = cg_load(cg_no - 1);
|
||||
struct cg *cg = cg_load(ald[ALDFILE_CG], cg_no - 1);
|
||||
if (!cg)
|
||||
return 0;
|
||||
gfx_init_texture_with_cg(&sp->texture, cg);
|
||||
@@ -433,7 +434,7 @@ int sact_SP_IsPtIn(int sp_no, int x, int y)
|
||||
int sact_CG_GetMetrics(int cg_no, union vm_value *cgm)
|
||||
{
|
||||
struct cg_metrics metrics;
|
||||
if (!cg_get_metrics(cg_no, &metrics))
|
||||
if (!cg_get_metrics(ald[ALDFILE_CG], cg_no, &metrics))
|
||||
return 0;
|
||||
cgm[0].i = metrics.w;
|
||||
cgm[1].i = metrics.h;
|
||||
@@ -15,15 +15,17 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include "system4.h"
|
||||
#include "ain.h"
|
||||
#include "cJSON.h"
|
||||
#include "heap.h"
|
||||
#include "page.h"
|
||||
#include "savedata.h"
|
||||
#include "system4.h"
|
||||
#include "system4/ain.h"
|
||||
#include "system4/string.h"
|
||||
#include "vm.h"
|
||||
#include "vm/heap.h"
|
||||
#include "vm/page.h"
|
||||
|
||||
static int current_global;
|
||||
|
||||
+2
-140
@@ -18,11 +18,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "heap.h"
|
||||
#include "system4.h"
|
||||
#include "utfsjis.h"
|
||||
#include "vm.h"
|
||||
#include "vm_string.h"
|
||||
#include "system4/string.h"
|
||||
#include "system4/utfsjis.h"
|
||||
|
||||
struct string EMPTY_STRING = {
|
||||
.cow = true,
|
||||
@@ -298,95 +296,6 @@ void string_set_char(struct string **_str, int i, unsigned int c)
|
||||
|
||||
#define DIGIT_MAX 512
|
||||
|
||||
enum fmt_type {
|
||||
FMT_VOID,
|
||||
FMT_INT,
|
||||
FMT_FLOAT,
|
||||
FMT_STRING,
|
||||
FMT_CHAR,
|
||||
FMT_BOOL
|
||||
};
|
||||
|
||||
struct fmt_spec {
|
||||
enum fmt_type type;
|
||||
int precision;
|
||||
int padding;
|
||||
bool zero_pad;
|
||||
bool zenkaku;
|
||||
};
|
||||
|
||||
static int read_number(const char **_fmt)
|
||||
{
|
||||
int n = 0;
|
||||
const char *fmt = *_fmt;
|
||||
while (*fmt && *fmt >= '0' && *fmt <= '9') {
|
||||
n *= 10;
|
||||
n += *fmt - '0';
|
||||
fmt++;
|
||||
}
|
||||
*_fmt = fmt;
|
||||
return n;
|
||||
}
|
||||
|
||||
static void parse_fmt_spec(const char **_fmt, struct fmt_spec *spec)
|
||||
{
|
||||
const char *fmt = *_fmt;
|
||||
memset(spec, 0, sizeof(struct fmt_spec));
|
||||
spec->precision = 6;
|
||||
while (*fmt) {
|
||||
switch (*fmt) {
|
||||
case 'd':
|
||||
spec->type = FMT_INT;
|
||||
goto end;
|
||||
case 'D':
|
||||
spec->type = FMT_INT;
|
||||
spec->zenkaku = true;
|
||||
goto end;
|
||||
case 'f':
|
||||
spec->type = FMT_FLOAT;
|
||||
goto end;
|
||||
case 'F':
|
||||
spec->type = FMT_FLOAT;
|
||||
spec->zenkaku = true;
|
||||
goto end;
|
||||
case 's':
|
||||
spec->type = FMT_STRING;
|
||||
goto end;
|
||||
case 'c':
|
||||
spec->type = FMT_CHAR;
|
||||
goto end;
|
||||
case 'b':
|
||||
spec->type = FMT_BOOL;
|
||||
goto end;
|
||||
case '0':
|
||||
spec->zero_pad = true;
|
||||
fmt++;
|
||||
break;
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
spec->padding = read_number(&fmt);
|
||||
break;
|
||||
case '.':
|
||||
fmt++;
|
||||
spec->precision = read_number(&fmt);
|
||||
break;
|
||||
default:
|
||||
goto warn;
|
||||
}
|
||||
}
|
||||
warn:
|
||||
WARNING("Invalid format specifier: %s", *_fmt);
|
||||
end:
|
||||
*_fmt = ++fmt;
|
||||
}
|
||||
|
||||
static int number_han2zen(char *buf, size_t size)
|
||||
{
|
||||
char *tmp = xmalloc(size*2);
|
||||
@@ -472,50 +381,3 @@ int float_to_cstr(char *buf, size_t size, float v, int figures, bool zero_pad, i
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
static void append_fmt(struct string **s, struct fmt_spec *spec, union vm_value arg)
|
||||
{
|
||||
int len;
|
||||
char buf[DIGIT_MAX] = { [DIGIT_MAX-1] = '\0' };
|
||||
switch (spec->type) {
|
||||
case FMT_VOID:
|
||||
return;
|
||||
case FMT_INT:
|
||||
len = int_to_cstr(buf, DIGIT_MAX, arg.i, spec->padding, spec->zero_pad, spec->zenkaku);
|
||||
string_append_cstr(s, buf, len);
|
||||
break;
|
||||
case FMT_FLOAT:
|
||||
len = float_to_cstr(buf, DIGIT_MAX, arg.f, spec->padding, spec->zero_pad, spec->precision, spec->zenkaku);
|
||||
string_append_cstr(s, buf, len);
|
||||
break;
|
||||
case FMT_STRING:
|
||||
string_append(s, heap[arg.i].s);
|
||||
break;
|
||||
case FMT_CHAR:
|
||||
string_push_back(s, arg.i);
|
||||
break;
|
||||
case FMT_BOOL:
|
||||
if (arg.i)
|
||||
string_append_cstr(s, "true", 4);
|
||||
else
|
||||
string_append_cstr(s, "false", 5);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
struct string *string_format(struct string *fmt, union vm_value arg)
|
||||
{
|
||||
struct string *out = string_ref(&EMPTY_STRING);
|
||||
for (const char *s = fmt->text; *s; s++) {
|
||||
if (*s == '%') {
|
||||
struct fmt_spec spec;
|
||||
string_append_cstr(&out, fmt->text, s - fmt->text);
|
||||
s++;
|
||||
parse_fmt_spec(&s, &spec);
|
||||
append_fmt(&out, &spec, arg);
|
||||
string_append_cstr(&out, s, strlen(s));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "system4.h"
|
||||
#include "utfsjis.h"
|
||||
#include "system4/utfsjis.h"
|
||||
|
||||
mem_alloc void *_xmalloc(size_t size, const char *func)
|
||||
{
|
||||
@@ -20,13 +20,14 @@
|
||||
#include <libgen.h>
|
||||
#include <dirent.h>
|
||||
#include <ctype.h>
|
||||
#include "system4.h"
|
||||
#include "ain.h"
|
||||
#include "ald.h"
|
||||
#include "debugger.h"
|
||||
#include "file.h"
|
||||
#include "ini.h"
|
||||
#include "utfsjis.h"
|
||||
#include "system4.h"
|
||||
#include "system4/ain.h"
|
||||
#include "system4/ald.h"
|
||||
#include "system4/utfsjis.h"
|
||||
#include "vm.h"
|
||||
|
||||
struct config config = {
|
||||
.game_name = NULL,
|
||||
+3
-3
@@ -17,9 +17,9 @@
|
||||
#include <SDL.h>
|
||||
#include <SDL_ttf.h>
|
||||
#include "system4.h"
|
||||
#include "gfx_core.h"
|
||||
#include "graphics.h"
|
||||
#include "utfsjis.h"
|
||||
#include "gfx/gfx.h"
|
||||
#include "gfx/types.h"
|
||||
#include "system4/utfsjis.h"
|
||||
|
||||
/*
|
||||
* NOTE: There are two different text rendering APIs: SACT2 and DrawGraph.
|
||||
@@ -26,8 +26,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "utfsjis.h"
|
||||
#include "s2utbl.h"
|
||||
#include "system4/utfsjis.h"
|
||||
#include "system4/s2utbl.h"
|
||||
|
||||
// Convert a character-index to a byte-index for a given SJIS string.
|
||||
int sjis_index(const char *_src, int index)
|
||||
@@ -20,11 +20,11 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "system4.h"
|
||||
#include "gfx_core.h"
|
||||
#include "gfx_private.h"
|
||||
#include "cg.h"
|
||||
#include "gfx/gfx.h"
|
||||
#include "gfx/private.h"
|
||||
#include "file.h"
|
||||
#include "system4.h"
|
||||
#include "system4/cg.h"
|
||||
|
||||
/*
|
||||
* Transform from the window coordinate system -> clip-space.
|
||||
+9
-9
@@ -22,18 +22,18 @@
|
||||
#include <time.h>
|
||||
#include <SDL.h> // for system.MsgBox
|
||||
|
||||
#include "system4.h"
|
||||
#include "vm.h"
|
||||
#include "vm_string.h"
|
||||
#include "page.h"
|
||||
#include "ain.h"
|
||||
#include "debugger.h"
|
||||
#include "file.h"
|
||||
#include "heap.h"
|
||||
#include "instructions.h"
|
||||
#include "little_endian.h"
|
||||
#include "savedata.h"
|
||||
#include "utfsjis.h"
|
||||
#include "debugger.h"
|
||||
#include "system4.h"
|
||||
#include "system4/ain.h"
|
||||
#include "system4/instructions.h"
|
||||
#include "system4/string.h"
|
||||
#include "system4/utfsjis.h"
|
||||
#include "vm.h"
|
||||
#include "vm/heap.h"
|
||||
#include "vm/page.h"
|
||||
|
||||
#define INITIAL_STACK_SIZE 4096
|
||||
#define HLL_MAX_ARGS 64
|
||||
Reference in New Issue
Block a user