From c31da0fe10d5efa85ee18f5ec4b6ec8018971463 Mon Sep 17 00:00:00 2001 From: kichikuou Date: Tue, 16 Nov 2021 09:10:07 +0900 Subject: [PATCH] Merge counter.c into cmdz.c --- modules/Gpx/Gpx.c | 1 - modules/NIGHTDLL/nt_event.c | 1 - modules/NIGHTDLL/nt_scenario.c | 1 - modules/NIGHTDLL/sprite_update.c | 1 - modules/SACT/sactlog.c | 1 - src/CMakeLists.txt | 2 +- src/cmdz.c | 60 ++++++++++++++++++----- src/counter.c | 84 -------------------------------- src/counter.h | 32 ------------ src/nact.c | 1 - src/xsystem35.c | 4 -- 11 files changed, 48 insertions(+), 140 deletions(-) delete mode 100644 src/counter.c delete mode 100644 src/counter.h diff --git a/modules/Gpx/Gpx.c b/modules/Gpx/Gpx.c index f2dfd62..a857b27 100644 --- a/modules/Gpx/Gpx.c +++ b/modules/Gpx/Gpx.c @@ -38,7 +38,6 @@ #include "ags.h" #include "cg.h" #include "image.h" -#include "counter.h" #include "input.h" // #include "alpha_plane.h" #include "surface.h" diff --git a/modules/NIGHTDLL/nt_event.c b/modules/NIGHTDLL/nt_event.c index 25c68e1..5583038 100644 --- a/modules/NIGHTDLL/nt_event.c +++ b/modules/NIGHTDLL/nt_event.c @@ -4,7 +4,6 @@ #include "portab.h" #include "system.h" -#include "counter.h" #include "menu.h" #include "input.h" #include "nact.h" diff --git a/modules/NIGHTDLL/nt_scenario.c b/modules/NIGHTDLL/nt_scenario.c index d43780b..e3f53e8 100644 --- a/modules/NIGHTDLL/nt_scenario.c +++ b/modules/NIGHTDLL/nt_scenario.c @@ -7,7 +7,6 @@ #include "portab.h" #include "system.h" -#include "counter.h" #include "input.h" #include "sdl_core.h" #include "xsystem35.h" diff --git a/modules/NIGHTDLL/sprite_update.c b/modules/NIGHTDLL/sprite_update.c index 5aef6f3..13739be 100644 --- a/modules/NIGHTDLL/sprite_update.c +++ b/modules/NIGHTDLL/sprite_update.c @@ -29,7 +29,6 @@ #include "portab.h" #include "system.h" #include "list.h" -#include "counter.h" #include "ags.h" #include "graphics.h" // #include "sact.h" diff --git a/modules/SACT/sactlog.c b/modules/SACT/sactlog.c index 4372234..b2ae123 100644 --- a/modules/SACT/sactlog.c +++ b/modules/SACT/sactlog.c @@ -30,7 +30,6 @@ #include "portab.h" #include "system.h" #include "list.h" -#include "counter.h" #include "menu.h" #include "input.h" #include "nact.h" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 807dbcb..a51b8af 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -58,7 +58,7 @@ target_sources(xsystem35 PRIVATE # Misc target_sources(xsystem35 PRIVATE - LittleEndian.c counter.c input.c profile.c mt19937-1.c filecheck.c mmap.c) + LittleEndian.c input.c profile.c mt19937-1.c filecheck.c mmap.c) # Scenario target_sources(xsystem35 PRIVATE diff --git a/src/cmdz.c b/src/cmdz.c index 700de9c..68607a1 100644 --- a/src/cmdz.c +++ b/src/cmdz.c @@ -30,7 +30,6 @@ #include "sdl_core.h" #include "ags.h" #include "scenario.h" -#include "counter.h" #include "randMT.h" #include "selection.h" #include "message.h" @@ -38,6 +37,31 @@ #include "nact.h" #include "font.h" +static struct { + uint32_t base; + int divisor; +} counters[257]; // [0] for ZT 1-5, [1..256] for ZT 10-11 + +static void reset_counter(int num, int divisor, int offset) { + counters[num].base = sdl_getTicks() - offset; + counters[num].divisor = divisor; +} + +static uint32_t get_counter(int num) { + // Allow up to 10 get_counter() calls in single animation frame. + static int frame = -1; + static int count = 0; + if (nact->frame_count == frame) { + if (++count >= 10) + nact->wait_vsync = TRUE; + } else { + frame = nact->frame_count; + count = 0; + } + + return sdl_getTicks() - counters[num].base; +} + void commandZC() { /* システムの使用環境を変更する */ int m = getCaliValue(); @@ -191,7 +215,7 @@ void commandZT0() { c1 = sl_getc(); c2 = sl_getc(); if (c1 == 0x41 && c2 == 0x7f) { - reset_counter(0); + reset_counter(0, 1, 0); return; } else { sl_jmpNear(sv); @@ -214,7 +238,7 @@ void commandZT1() { /* タイマーを n の数値でクリアする */ int n = getCaliValue(); - reset_counter(n); + reset_counter(0, 1, n); DEBUG_COMMAND("ZT1 %d:\n", n); } @@ -222,7 +246,7 @@ void commandZT1() { void commandZT2() { /* タイマーを var に取得する 1/10 sec */ int *var = getCaliVariable(); - int val = get_counter(100); + int val = get_counter(0) / 100; if (val > 65535) val = 65535; *var = val; @@ -233,7 +257,7 @@ void commandZT2() { void commandZT3() { /* タイマーを var に取得する 1/30 sec */ int *var = getCaliVariable(); - int val = get_counter(33); + int val = get_counter(0) * 3 / 100; if (val > 65535) val = 65535; *var = val; @@ -244,7 +268,7 @@ void commandZT3() { void commandZT4() { /* タイマーを var に取得する 1/60 sec */ int *var = getCaliVariable(); - int val = get_counter(17); + int val = get_counter(0) * 3 / 50; if (val > 65535) val = 65535; *var = val; @@ -255,7 +279,7 @@ void commandZT4() { void commandZT5() { /* タイマーを var に取得する */ int *var = getCaliVariable(); - int val = get_counter(10); + int val = get_counter(0) / 10; if (val > 65535) val = 65535; *var = val; @@ -269,7 +293,14 @@ void commandZT10() { int base = getCaliValue(); int count = getCaliValue(); - reset_counter_high(num, base ? base : 1, count); + if (num > 256) { + WARNING("invalid timer id %d\n", num); + } else if (num == 0) { + for (int i = 1; i <= 256; i++) + reset_counter(i, base, count); + } else { + reset_counter(num, base, count); + } DEBUG_COMMAND("ZT10 %d,%d,%d:\n", num, base, count); } @@ -278,11 +309,14 @@ void commandZT11() { /* 高精度タイマー取得 */ int num = getCaliValue(); int *var = getCaliVariable(); - int val = get_high_counter(num); - - *var = val; - - DEBUG_COMMAND("ZT11 %d,%d,%d:\n", num, val, *var); + + int divisor = counters[num].divisor ? counters[num].divisor : 1; + if (num > 256) + WARNING("invalid timer id %d\n", num); + else + *var = get_counter(num) / divisor; + + DEBUG_COMMAND("ZT11 %d,%d:\n", num, *var); } void commandZT20() { diff --git a/src/counter.c b/src/counter.c deleted file mode 100644 index e6e8ea4..0000000 --- a/src/counter.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * counter.c 内部カウンタ - * - * 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 - * - * -*/ -/* $Id: counter.c,v 1.10 2000/11/25 13:09:03 chikama Exp $ */ - -#include "counter.h" -#include "sdl_core.h" -#include "nact.h" - -#define NUM_COUNTER 257 - -static uint32_t base_ticks[NUM_COUNTER]; -static int offsets[NUM_COUNTER]; -static int divisions[NUM_COUNTER] = { [0 ...( NUM_COUNTER-1 )]=1}; - -static void counter_init(int num, int offset, int division) { - base_ticks[num] = sdl_getTicks(); - offsets[num] = offset; - divisions[num] = division; -} - -static int get_counter_internal(int num, int division) { - // Allow up to 10 get_counter() calls in single animation frame. - static int frame = -1; - static int count = 0; - if (nact->frame_count == frame) { - if (++count >= 10) - nact->wait_vsync = TRUE; - } else { - frame = nact->frame_count; - count = 0; - } - - uint32_t ms = sdl_getTicks() - base_ticks[num] + offsets[num]; - return ms / division; -} - -int get_counter(int division) { - return get_counter_internal(0, division); -} - -/* カウンタ〜を valでリセット */ -/* 初期化時に一度呼んでおく */ -void reset_counter(int val) { - counter_init(0, val, 1); -} - - -int get_high_counter(int num) { - return get_counter_internal(num, divisions[num]); -} - -/* 高精度カウンタ〜 thanx tajiri@wizard */ -/* カウンタ〜を valでリセット */ -/* 初期化時に一度呼んでおく */ -void reset_counter_high(int num, int division, int val) { - if (num) { - counter_init(num, val, division); - } else { - for (int i = 1; i <= 256; i++) - counter_init(i, val, division); - } -} - - diff --git a/src/counter.h b/src/counter.h deleted file mode 100644 index 5e2a547..0000000 --- a/src/counter.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * counter.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 - * -*/ -/* $Id: counter.h,v 1.7 2000/11/25 13:09:03 chikama Exp $ */ - -#ifndef __XSYSTEM35_COUNTER__ -#define __XSYSTEM35_COUNTER__ - -extern int get_counter(int division); -extern void reset_counter(int val); -extern int get_high_counter(int num); -extern void reset_counter_high(int num, int division, int val); - -#endif /* !__XSYSTEM35_COUNTER__ */ diff --git a/src/nact.c b/src/nact.c index 52c690d..6836869 100644 --- a/src/nact.c +++ b/src/nact.c @@ -33,7 +33,6 @@ #include "xsystem35.h" #include "sdl_core.h" #include "ags.h" -#include "counter.h" #include "nact.h" #include "debugger.h" #include "selection.h" diff --git a/src/xsystem35.c b/src/xsystem35.c index f313748..6504f63 100644 --- a/src/xsystem35.c +++ b/src/xsystem35.c @@ -58,7 +58,6 @@ #include "nact.h" #include "profile.h" #include "randMT.h" -#include "counter.h" #include "ags.h" #include "font.h" #include "sdl_core.h" @@ -222,9 +221,6 @@ static void sys35_init() { sdl_setFullscreen(fs_on); nact->noantialias = font_noantialias; ags_setAntialiasedStringMode(!font_noantialias); - - - reset_counter(0); sgenrand(getpid());