mirror of
https://github.com/kichikuou/xsystem35-sdl2.git
synced 2026-10-10 08:08:34 +03:00
Merge counter.c into cmdz.c
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
#include "portab.h"
|
||||
#include "system.h"
|
||||
#include "counter.h"
|
||||
#include "menu.h"
|
||||
#include "input.h"
|
||||
#include "nact.h"
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include "portab.h"
|
||||
#include "system.h"
|
||||
#include "counter.h"
|
||||
#include "input.h"
|
||||
#include "sdl_core.h"
|
||||
#include "xsystem35.h"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+47
-13
@@ -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() {
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
* counter.c 内部カウンタ
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*
|
||||
*/
|
||||
/* $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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* counter.h 内部カウンタ
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
/* $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__ */
|
||||
@@ -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"
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user