This repository has been archived by the owner on Oct 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Lvns.c
451 lines (380 loc) · 9.65 KB
/
Lvns.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
/*
* LEAF Visual Novel System For X
* (c) Copyright 1999,2000 Go Watanabe mailto:[email protected]
* All rights reserverd.
*
* ORIGINAL LVNS (c) Copyright 1996-1999 LEAF/AQUAPLUS Inc.
*
* $Id: Lvns.c,v 1.30 2001/08/12 11:35:43 tf Exp $
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Lvns.h"
#include "LvnsEffect.h"
/**
* LVNS 生成
*/
Lvns *
LvnsNew(void)
{
Lvns *lvns;
dprintf((stderr, "system initialize...\n"));
if ((lvns = malloc(sizeof *lvns)) == NULL)
return NULL;
lvns->data_path = strdup(".");
lvns->savedata_path = NULL;
/* ---------------------------------------------------------- */
/* シナリオパーサ初期化 */
lvns->start_scn_num = -1;
lvns->scn_data = NULL;
lvns->scn_text = NULL;
lvns->scn_current = 0;
lvns->image_mode = False;
lvns->fast_text = False;
lvns->skip = False;
lvns->char_wait_time = 1; /* tick */
lvns->force_skip = False;
lvns->fast_when_seen = True;
lvns->key_click_fast = True;
lvns->enable_effect = True;
lvns->enable_effect_back = True;
lvns->seen_mode = False;
lvns->demo_mode = False;
/* ------------------------------------------------------ */
/* テキストレイヤ処理系 */
lvns->current_tvram = 1;
LvnsClearText(lvns);
lvns->current_tvram = 0;
LvnsClearText(lvns);
lvns->cursor_state = 0;
lvns->text_cursor_state = 0;
lvns->text_attr = 0;
/* -------------------------------------------------------- */
/* 画像描画系初期化 */
lvns->latitude = 16;
lvns->latitude_dark = 11;
lvns->sepia_mode_next = False;
lvns->sepia_mode = False;
lvns->effect_back = NULL;
lvns->effect_back_next = NULL;
lvns->effect_back_state = 0;
lvns->disp_func = NULL;
/* -------------------------------------------------------- */
/* 音楽再生系初期化 */
lvns->current_music = 0;
lvns->next_music = 0;
lvns->loop_music = False;
lvns->current_music_volume = 255;
lvns->music_fade_mode = False;
lvns->music_fade_flag = 0;
lvns->music = NULL;
/* --------------------------------------------------------- */
/* SE 関連初期化 */
lvns->sound_loop = False;
lvns->sound_count = 0;
lvns->sound = NULL;
/* --------------------------------------------------------- */
/* ヒストリ関連初期化 */
lvns->history = NULL;
lvns->history_pos = 0;
lvns->history_size = 0;
return lvns;
}
/**
* LVNS 初期化
* @param type ゲーム種別
* @param depend システム依存情報
*/
void
LvnsInitialize(Lvns *lvns, int type, void *depend)
{
lvns->system_depend = depend;
/* モジュール別処理 */
switch (type) {
case 0:
SizukuInitialize(lvns);
break;
case 1:
KizuatoInitialize(lvns);
break;
case 2:
ToHeartInitialize(lvns);
break;
}
/* 内部画面バッファ生成 */
lvns->background = lvnsimage_new(WIDTH, HEIGHT, 0, 0);
lvns->vram = lvnsimage_new(WIDTH, HEIGHT, 0, 0);
LVNS->clearScreen(lvns);
dprintf((stderr, "data loading...\n"));
{
/* データ読み出し用パス */
char path[1024];
/* コード変換テーブルの読み込み */
{
FILE *fp;
size_t size;
int i;
if ((fp = fopen(LVNS->fonttable_name, "r")) == NULL) {
snprintf(path, sizeof path, "%s/%s", lvns->data_path, LVNS->fonttable_name);
if ((fp = fopen(path, "r")) == NULL) {
perror(path);
exit(1);
}
}
fseek(fp, 0, SEEK_END);
size = ftell(fp);
rewind(fp);
/* 変換用テーブルよみこみ */
lvns->leaf_to_euc = malloc(size);
if (fread(lvns->leaf_to_euc, 1, size, fp) != size) {
perror(LVNS->fonttable_name);
free(lvns->leaf_to_euc);
exit(1);
}
fclose(fp);
/* 逆変換用テーブル作成 */
size /= 2; /* 文字数 */
lvns->jis_to_leaf = (u_short *)
malloc(sizeof(u_short) * 94 * 94);
/* 初期化 */
for (i=0; i < 94 * 94; i++) {
lvns->jis_to_leaf[i] = 0;
}
/* マッピング */
for (i=0; i < size; i++) {
int code = ((lvns->leaf_to_euc[i*2 ] & 0x7f) - 33) * 94 +
(lvns->leaf_to_euc[i*2+1] & 0x7f) - 33;
lvns->jis_to_leaf[code] = i;
}
}
/* データパッケージオープン */
snprintf(path, sizeof path, "%s/%s", lvns->data_path, LVNS->leafpack_name);
if ((lvns->leafpack = leafpack_new(path)) == NULL) {
if ((lvns->leafpack = leafpack_new(LVNS->leafpack_name)) == NULL) {
fprintf(stderr, "Can't open package %s.\n", LVNS->leafpack_name);
exit(1);
}
}
/* シナリオパッケージオープン */
if ((LVNS->scnpack_name)) {
snprintf(path, sizeof path, "%s/%s", lvns->data_path, LVNS->scnpack_name);
if ((lvns->scnpack = leafpack_new(path)) == NULL) {
if ((lvns->scnpack = leafpack_new(LVNS->scnpack_name)) == NULL) {
fprintf(stderr, "Can't open package %s.\n",
LVNS->scnpack_name);
exit(1);
}
}
} else {
lvns->scnpack = lvns->leafpack;
}
/* フォントデータ読み込み */
if (!(lvns->leaf_font_data=LvnsLoadData(lvns, "KNJ_ALL.KNJ", NULL))){
fprintf(stderr, "Can't open KNJ_ALL.KNJ.\n");
exit(1);
}
}
}
/**
* LVNS 破棄
*/
void
LvnsDestroy(Lvns *lvns)
{
if (lvns) {
/* シナリオデータ解放 */
free(lvns->scn_data);
free(lvns->scn_text);
/* データパッケージ解放 */
leafpack_delete(lvns->leafpack);
/* シナリオパッケージ解放 */
if (LVNS->scnpack_name)
leafpack_delete(lvns->scnpack);
/* フォントデータ解放 */
free(lvns->leaf_font_data);
/* セーブデータパス情報開放 */
if (lvns->savedata_path) {
free(lvns->savedata_path);
}
/* データパス情報開放 */
if (lvns->data_path) {
free(lvns->data_path);
}
/* ヒストリ情報廃棄 */
if (lvns->history) {
free(lvns->history);
}
/* 自分自身を破棄 */
free(lvns);
}
}
/**
* 内部関数インターバル実行処理
*/
static void
Interval(Lvns *lvns, Bool redisp_ok)
{
/* BGM の処理 */
if (lvns->current_music) {
/* フェード処理 */
if (lvns->music_fade_mode) {
int vol, fade;
if (lvns->music_fade_flag) {
fade = 256 * 2 * 10 / INTERVAL; /* 0.5秒以内 */
} else {
fade = - 256 * 2 * 10 / INTERVAL; /* 0.5秒以内 */
}
vol = lvns->current_music_volume + fade;
if (vol <= 0) {
vol = 0;
}
if (vol >= 255) {
vol = 255;
}
if (lvns->music_fade_flag) {
if (vol == 255) {
lvns->music_fade_mode = False;
lvns->music_fade_flag = False;
}
} else {
if (vol == 0) {
lvns->music_fade_mode = False;
lvns->music_fade_flag = True;
}
}
LvnsSetMusicVolume(lvns, vol);
if (vol == 0)
LvnsPauseMusic(lvns);
}
if (lvns->loop_music)
LvnsLoopMusic(lvns);
}
if (lvns->sound_loop || lvns->sound_count)
LvnsLoopSound(lvns);
/* 背景画像処理 */
if (lvns->effect_back && lvns->enable_effect_back) {
LvnsBackEffectSetState(lvns);
#ifdef USE_MGL
MglGetEvent(lvns, 1);
#endif
if (redisp_ok) {
LvnsBackEffect(lvns);
LvnsDispWindow(lvns);
} else {
LvnsBackEffect(lvns);
}
}
}
/**
* 画面フリップ待ち
*/
void
LvnsFlip(Lvns *lvns, Bool redisp_ok)
{
Interval(lvns, redisp_ok);
lvns->flip(lvns);
}
/*
* 処理メインエンジン
*/
void
LvnsMain(Lvns *lvns)
{
/* BGM系初期化 */
MusicOpen(lvns->music);
/* SE系初期化 */
SoundOpen(lvns->sound);
/* 各種初期化 */
LVNS->start(lvns);
/* 大域ジャンプ用 */
switch ((LvnsJumpParameter)setjmp(lvns->jump)) {
case LVNS_JUMP_NONE: /* 初回 */
break;
case LVNS_JUMP_RESTART:
goto main_start;
case LVNS_JUMP_TITLE:
goto title;
case LVNS_JUMP_END:
goto end;
}
if (lvns->start_scn_num >= 0) {
/* デバッグ用シナリオ指定起動 */
LvnsInitSavePoint(lvns, &lvns->savepoint);
lvns->savepoint.scn = lvns->start_scn_num;
lvns->savepoint.blk = 1;
lvns->savepoint.scn_offset = 0;
} else {
/* 起動時ジングル & オープニング */
LVNS->jingle(lvns);
LVNS->opening(lvns);
}
main_start:
while (1) {
lvns->history_pos = 0;
lvns->latitude = 16;
LVNS->main(lvns);
/* BGM停止 */
LvnsStopMusic(lvns);
LvnsStopSound(lvns);
/* 画面消去 */
lvns->current_tvram = 0;
LvnsClearText(lvns);
LvnsClear(lvns, LVNS_EFFECT_WIPE_TTOB);
title:
lvns->latitude = 16;
LVNS->title(lvns);
}
end:
/* サウンド系終了 */
SoundClose(lvns->sound);
/* BGM系終了 */
MusicClose(lvns->music);
}
/**
* 時間待ち
* 指定した回数のフリップ分待つ
*/
void
LvnsWait(Lvns *lvns, int flip_cnt)
{
while (flip_cnt-- > 0) {
LvnsFlip(lvns, True);
}
}
/**
* 大域ジャンプ処理
*/
void
LvnsJump(Lvns *lvns, LvnsJumpParameter param)
{
LvnsSetDispFunc(lvns, NULL, NULL);
longjmp(lvns->jump, (int)param);
fprintf(stderr, "warning: bad jump!: %d\n", param);
exit(1);
}
/**
* ファイル保存パス設定
*/
void
LvnsSetSaveDataPath(Lvns *lvns, const char *path)
{
if (lvns->savedata_path) {
free(lvns->savedata_path);
}
lvns->savedata_path = strdup(path);
}
void
LvnsSetDataPath(Lvns *lvns, const char *path)
{
if (lvns->data_path) {
free(lvns->data_path);
}
lvns->data_path = strdup(path);
}
void
LvnsSetDispFunc(Lvns *lvns, void (*func)(Lvns *lvns, void *data), void *data)
{
lvns->disp_func = func;
lvns->disp_func_param = data;
}