diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7eb9bdf..7d6bcf3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,8 +1,26 @@ +# src_lib contains sources that can be unit-tested without linking the +# rest of xsystem35. They may reference sys_* and other small hooks; +# tests provide stub definitions for those. add_library(src_lib STATIC + ald_manager.c + alpha_plane.c + audio_meta.c + bmp.c + cache.c + cali.c + dri.c + filecheck.c gameresource.c hankaku.c + mmap.c msgqueue.c + pms.c + profile.c + qnt.c + scenario.c utfsjis.c + variable.c + vsp.c ) target_compile_options(src_lib PRIVATE -Wno-pointer-sign -Wall) target_include_directories(src_lib PRIVATE .) @@ -22,12 +40,6 @@ target_link_libraries(xsystem35 PRIVATE src_lib) target_sources(xsystem35 PRIVATE ags.c - ald_manager.c - alpha_plane.c - audio_meta.c - bmp.c - cache.c - cali.c cdrom.bgm.c cg.c cmd2F.c @@ -57,11 +69,9 @@ target_sources(xsystem35 PRIVATE cmdy.c cmdz.c cursor.c - dri.c ecopy.c effect.c event.c - filecheck.c font.c hacks.c gfx_draw.c @@ -75,7 +85,6 @@ target_sources(xsystem35 PRIVATE message.c microui/microui.c midi.c - mmap.c modal.c msgskip.c mt19937-1.c @@ -84,19 +93,13 @@ target_sources(xsystem35 PRIVATE music_midi.c nact.c network.c - pms.c - profile.c - qnt.c s39ain.c savedata.c - scenario.c scheduler.c selection.c system.c texthook.c - variable.c volume.c - vsp.c xsystem35.c ) diff --git a/src/cali.c b/src/cali.c index 9ba096e..0ef91ea 100644 --- a/src/cali.c +++ b/src/cali.c @@ -24,10 +24,10 @@ #include #include #include "portab.h" +#include "system.h" +#include "cali.h" #include "variable.h" #include "scenario.h" -#include "nact.h" -#include "xsystem35.h" #define OP_AND 0x74 #define OP_OR 0x75 diff --git a/src/cali.h b/src/cali.h new file mode 100644 index 0000000..700f10e --- /dev/null +++ b/src/cali.h @@ -0,0 +1,35 @@ +/* + * cali.h 計算式の評価 + * + * Copyright (C) 1997-1998 Masaki Chikama (Wren) + * 1998- + * + * 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 __CALI_H__ +#define __CALI_H__ + +#include "portab.h" + +struct VarRef; + +int getCaliValue(void); +int *getCaliVariable(void); +bool getCaliArray(struct VarRef *ref); +int *getVariable(void); + +#endif /* !__CALI_H__ */ diff --git a/src/message.c b/src/message.c index 9bffdd7..6c38c6d 100644 --- a/src/message.c +++ b/src/message.c @@ -262,6 +262,20 @@ void msg_setMessageLocation(int x, int y) { nextLineIsAfterKaigyou = false; } +void sl_restoreTextColor(uint8_t type, uint8_t color) { + if (type) + nact->sel.MsgFontColor = color; + else + msg.MsgFontColor = color; +} + +void sl_restoreTextSize(uint8_t type, int size) { + if (type) + nact->sel.MsgFontSize = size; + else + msg.MsgFontSize = size; +} + void msg_getMessageLocation(SDL_Point *loc) { loc->x = msgcur.x; loc->y = msgcur.y; diff --git a/src/nact.c b/src/nact.c index e624037..98eb281 100644 --- a/src/nact.c +++ b/src/nact.c @@ -69,6 +69,7 @@ void sys_setHankakuMode(int mode) { void sys_setCharacterEncoding(CharacterEncoding encoding) { nact->encoding = encoding; + v_set_encoding(encoding); } /* 選択肢・通常メッセージ振り分け */ @@ -146,6 +147,7 @@ void nact_init() { nact->is_va_animation = false; nact->is_cursor_animation = false; nact->encoding = SHIFT_JIS; + v_set_encoding(SHIFT_JIS); free(nact->game_title_utf8); nact->game_title_utf8 = NULL; diff --git a/src/nact.h b/src/nact.h index 8230ced..18f932d 100644 --- a/src/nact.h +++ b/src/nact.h @@ -25,6 +25,7 @@ #define __NACT_H__ #include "portab.h" +#include "cali.h" #include "s39ain.h" #include "gameresource.h" #include "selection.h" @@ -47,13 +48,6 @@ extern void nact_init(); extern void nact_reset(void); extern void nact_quit(bool restart); -// cali.c -struct VarRef; -int getCaliValue(void); -int *getCaliVariable(void); -bool getCaliArray(struct VarRef *ref); -int *getVariable(void); - // cmd_check.c extern void exec_command(void); diff --git a/src/s39ain.c b/src/s39ain.c index 7c8e680..0a550ce 100644 --- a/src/s39ain.c +++ b/src/s39ain.c @@ -147,6 +147,7 @@ bool s39ain_init(const char *path_to_ain, S39AIN *ain) { ain->var[i] = p; p += strlen(p) + 1; } + v_set_names(ain->varnum, ain->var); } /* check MSGI */ diff --git a/src/scenario.c b/src/scenario.c index 22372d5..2e80fdd 100644 --- a/src/scenario.c +++ b/src/scenario.c @@ -27,10 +27,11 @@ #include "portab.h" #include "ald_manager.h" +#include "message.h" +#include "savedata.h" #include "variable.h" #include "scenario.h" #include "LittleEndian.h" -#include "xsystem35.h" const uint8_t *sl_sco; int sl_page; @@ -682,20 +683,14 @@ static void pop_state(uint8_t tag) { { uint8_t color = stack_pop_byte(); uint8_t type = stack_pop_byte(); - if (type) - nact->sel.MsgFontColor = color; - else - nact->msg.MsgFontColor = color; + sl_restoreTextColor(type, color); } break; case STACK_TEXTSIZE: { int size = stack_pop_dword(); uint8_t type = stack_pop_byte(); - if (type) - nact->sel.MsgFontSize = size; - else - nact->msg.MsgFontSize = size; + sl_restoreTextSize(type, size); } break; case STACK_TEXTLOC: diff --git a/src/scenario.h b/src/scenario.h index d61236a..f731a31 100644 --- a/src/scenario.h +++ b/src/scenario.h @@ -96,6 +96,11 @@ void sl_pushTextLoc(int x, int y); void sl_popState(uint8_t expected_type); struct stack_frame_info *sl_next_stack_frame(struct stack_frame_info *frame_info); +// Hooks called when text state is popped from the stack. +// Implemented in message.c; unit tests provide their own stubs. +void sl_restoreTextColor(uint8_t type, uint8_t color); +void sl_restoreTextSize(uint8_t type, int size); + static inline int sl_getIndex(void) { return sl_index; } static inline int sl_getPage(void) { return sl_page; } static inline int sl_getc(void) { return sl_sco[sl_index++]; } diff --git a/src/variable.c b/src/variable.c index 5039fe9..463dafa 100644 --- a/src/variable.c +++ b/src/variable.c @@ -25,9 +25,9 @@ #include #include #include "portab.h" +#include "system.h" #include "utfsjis.h" #include "variable.h" -#include "xsystem35.h" // For some reasons, System3.9's initial system page size is 65537. #define SYSVAR_MAX 65537 @@ -54,9 +54,24 @@ double longVar[SYSVARLONG_MAX]; static char **strVar; static int strvar_cnt; +// Encoding of string variables +static CharacterEncoding encoding = SHIFT_JIS; +// Variable name table (defined in System39.ain) +static int varname_cnt; +static char **varnames; + +void v_set_encoding(CharacterEncoding e) { + encoding = e; +} + +void v_set_names(int count, char **names) { + varname_cnt = count; + varnames = names; +} + const char *v_name(int var) { - if (var < nact->ain.varnum) - return nact->ain.var[var]; + if (var < varname_cnt) + return varnames[var]; static char buf[10]; sprintf(buf, "VAR%d", var); return buf; @@ -64,7 +79,7 @@ const char *v_name(int var) { static char *advance(const char *s, int n) { while (*s && n > 0) { - s = advance_char(s, nact->encoding); + s = advance_char(s, encoding); n--; } return (char *)s; @@ -264,7 +279,7 @@ size_t svar_length(int no) { int c = 0; while (*s) { - s = advance_char(s, nact->encoding); + s = advance_char(s, encoding); c++; } return c; @@ -299,7 +314,7 @@ int svar_find(int no, int start, const char *str) { return -1; int n = 0; while (p < found) { - p = advance_char(p, nact->encoding); + p = advance_char(p, encoding); n++; } return n; diff --git a/src/variable.h b/src/variable.h index d5b69cc..9ec87a6 100644 --- a/src/variable.h +++ b/src/variable.h @@ -26,6 +26,7 @@ #include #include "portab.h" +#include "utfsjis.h" struct VarPage { int size; @@ -50,6 +51,8 @@ static inline int v_sliceSize(struct VarRef *r) { return varPage[r->page].size - r->index; } +void v_set_encoding(CharacterEncoding encoding); +void v_set_names(int count, char **names); const char *v_name(int var); int *v_ref_indexed(int var, int index, struct VarRef *ref); bool v_allocatePage(int page, int size, bool saveflag);