Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dosbox-staging/dosbox-staging.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirk <kklobe@gmail.com>2021-10-06 06:04:47 +0300
committerKirk <kklobe@gmail.com>2021-10-07 02:23:14 +0300
commitfd0ff5c05593ca56ba4e903fab32ca7586487a86 (patch)
tree93a7c8691f26f79865364cf90c32273270e84519
parentc1b923c47ef62f27ea6a535e0d337d3ce3816108 (diff)
Migrate PIC to std::chronokk/convert-ticks-to-chrono-1
-rw-r--r--include/pic.h6
-rw-r--r--src/gui/render.cpp3
-rw-r--r--src/hardware/adlib.cpp31
-rw-r--r--src/hardware/adlib.h2
-rw-r--r--src/hardware/disney.cpp8
-rw-r--r--src/hardware/gameblaster.cpp4
-rw-r--r--src/hardware/hardware.cpp6
-rw-r--r--src/hardware/innovation.cpp8
-rw-r--r--src/hardware/innovation.h3
-rw-r--r--src/hardware/joystick.cpp5
-rw-r--r--src/hardware/pic.cpp4
-rw-r--r--src/hardware/ps1audio.cpp14
-rw-r--r--src/hardware/tandy_sound.cpp4
13 files changed, 53 insertions, 45 deletions
diff --git a/include/pic.h b/include/pic.h
index cc6af1737..9dd6bc0ca 100644
--- a/include/pic.h
+++ b/include/pic.h
@@ -23,6 +23,8 @@
#include <cmath>
#include <cstdint>
+#include "timer.h"
+
/* CPU Cycle Timing */
extern int32_t CPU_Cycles;
extern int32_t CPU_CycleLeft;
@@ -35,7 +37,7 @@ extern uint32_t PIC_IRQCheck;
// Elapsed milliseconds since starting DOSBox
// Holds ~4.2 B milliseconds or ~48 days before rolling over
-extern uint32_t PIC_Ticks;
+extern system_tick_t PIC_Ticks;
// The number of cycles not done yet (ND)
static inline int32_t PIC_TickIndexND()
@@ -59,7 +61,7 @@ static inline int32_t PIC_MakeCycles(double amount)
static inline double PIC_FullIndex()
{
- return static_cast<double>(PIC_Ticks) + PIC_TickIndex();
+ return static_cast<double>(PIC_Ticks.count()) + PIC_TickIndex();
}
void PIC_ActivateIRQ(uint8_t irq);
diff --git a/src/gui/render.cpp b/src/gui/render.cpp
index 3164112af..47fcfaa4f 100644
--- a/src/gui/render.cpp
+++ b/src/gui/render.cpp
@@ -37,6 +37,7 @@
#include "support.h"
#include "shell.h"
#include "string_utils.h"
+#include "timer.h"
#include "vga.h"
#include "render_crt_glsl.h"
@@ -210,7 +211,7 @@ static void RENDER_Halt( void ) {
render.active=false;
}
-extern uint32_t PIC_Ticks;
+extern system_tick_t PIC_Ticks;
void RENDER_EndUpdate( bool abort ) {
if (GCC_UNLIKELY(!render.updating))
return;
diff --git a/src/hardware/adlib.cpp b/src/hardware/adlib.cpp
index 312df1033..43f30d62a 100644
--- a/src/hardware/adlib.cpp
+++ b/src/hardware/adlib.cpp
@@ -23,11 +23,14 @@
#include <math.h>
#include <sys/types.h>
+#include <chrono>
+
#include "cpu.h"
#include "setup.h"
#include "support.h"
#include "mapper.h"
#include "mem.h"
+#include "timer.h"
#include "dbopl.h"
#include "../libs/nuked/opl3.h"
@@ -232,7 +235,7 @@ struct RawHeader {
Bit16u versionHigh; /* 0x08, size of the data following the m */
Bit16u versionLow; /* 0x0a, size of the data following the m */
Bit32u commands; /* 0x0c, Bit32u amount of command/data pairs */
- Bit32u milliseconds; /* 0x10, Bit32u Total milliseconds of data in this chunk */
+ std::chrono::milliseconds milliseconds; /* 0x10, Bit32u Total milliseconds of data in this chunk */
Bit8u hardware; /* 0x14, Bit8u Hardware Type 0=opl2,1=dual-opl2,2=opl3 */
Bit8u format; /* 0x15, Bit8u Format 0=cmd/data interleaved, 1 maybe all cdms, followed by all data */
Bit8u compression; /* 0x16, Bit8u Compression Type, 0 = No Compression */
@@ -259,8 +262,8 @@ class Capture {
RawHeader header;
FILE* handle = nullptr; // File used for writing
- Bit32u startTicks = 0; // Start used to check total raw length on end
- Bit32u lastTicks = 0; // Last ticks when last last cmd was added
+ system_tick_t startTicks = 0ms; // Start used to check total raw length on end
+ system_tick_t lastTicks = 0ms; // Last ticks when last last cmd was added
Bit8u buf[1024]; // 16 added for delay commands and what not
Bit32u bufUsed = 0;
@@ -380,7 +383,7 @@ class Capture {
header.versionHigh = host_to_le(header.versionHigh);
header.versionLow = host_to_le(header.versionLow);
header.commands = host_to_le(header.commands);
- header.milliseconds = host_to_le(header.milliseconds);
+ header.milliseconds = static_cast<std::chrono::milliseconds>(host_to_le(static_cast<uint64_t>(header.milliseconds.count())));
fseek( handle, 0, SEEK_SET );
fwrite( &header, 1, sizeof( header ), handle );
fclose( handle );
@@ -405,25 +408,25 @@ public:
if ( (*cache)[ regFull ] == val )
return true;
/* Check how much time has passed */
- uint32_t passed = PIC_Ticks - lastTicks;
+ auto passed = PIC_Ticks - lastTicks;
lastTicks = PIC_Ticks;
header.milliseconds += passed;
//if ( passed > 0 ) LOG_MSG( "Delay %d", passed ) ;
// If we passed more than 30 seconds since the last command, we'll restart the the capture
- if ( passed > 30000 ) {
+ if ( passed > 30000ms ) {
CloseFile();
goto skipWrite;
}
- while (passed > 0) {
- if (passed < 257) { //1-256 millisecond delay
- AddBuf( delay256, passed - 1 );
- passed = 0;
+ while (passed > 0ms) {
+ if (passed < 257ms) { //1-256 millisecond delay
+ AddBuf( delay256, passed.count() - 1 );
+ passed = 0ms;
} else {
- const auto shift = (passed >> 8);
- passed -= shift << 8;
- AddBuf( delayShift8, shift - 1 );
+ const auto shift = (passed / 256);
+ passed -= shift * 256;
+ AddBuf( delayShift8, shift.count() - 1 );
}
}
AddWrite( regFull, val );
@@ -744,7 +747,7 @@ static void OPL_CallBack(uint16_t len)
{
module->handler->Generate(module->mixerChan, len);
// Disable the sound generation after 30 seconds of silence
- if ((PIC_Ticks - module->lastUsed) > 30000) {
+ if ((PIC_Ticks - module->lastUsed) > 30000ms) {
uint8_t i;
for (i=0xb0;i<0xb9;i++) if (module->cache[i]&0x20||module->cache[i+0x100]&0x20) break;
if (i==0xb9) module->mixerChan->Enable(false);
diff --git a/src/hardware/adlib.h b/src/hardware/adlib.h
index dfd957b90..84b43c5dd 100644
--- a/src/hardware/adlib.h
+++ b/src/hardware/adlib.h
@@ -179,7 +179,7 @@ class Module: public Module_base {
public:
static OPL_Mode oplmode;
MixerChannel* mixerChan;
- Bit32u lastUsed; //Ticks when adlib was last used to turn of mixing after a few second
+ system_tick_t lastUsed; //Ticks when adlib was last used to turn of mixing after a few second
Handler* handler; //Handler that will generate the sound
RegisterCache cache;
diff --git a/src/hardware/disney.cpp b/src/hardware/disney.cpp
index dfc92e668..2777956e4 100644
--- a/src/hardware/disney.cpp
+++ b/src/hardware/disney.cpp
@@ -56,7 +56,7 @@ struct Disney {
// the D/A channels
dac_channel da[2] = {};
- Bitu last_used = 0;
+ system_tick_t last_used = 0ms;
mixer_channel_ptr_t chan{nullptr, MIXER_DelChannel};
bool stereo = false;
@@ -80,7 +80,7 @@ static void DISNEY_disable(uint32_t)
disney.chan->AddSilence();
disney.chan->Enable(false);
}
- disney.last_used = 0;
+ disney.last_used = 0ms;
disney.state = DISNEY_STATE::IDLE;
disney.interface_det = 0;
disney.interface_det_ext = 0;
@@ -360,7 +360,7 @@ static void DISNEY_CallBack(uint16_t len) {
//LOG_MSG("disney underflow %d",len - real_used);
}
- if (disney.last_used+100<PIC_Ticks) {
+ if (disney.last_used+100ms<PIC_Ticks) {
// disable sound output
PIC_AddEvent(DISNEY_disable, 0.0001); // I think we shouldn't delete the
// mixer while we are inside it
@@ -406,7 +406,7 @@ void DISNEY_Init(Section* sec) {
// Initialize the Disney states
disney.status = DISNEY_INIT_STATUS;
disney.control = 0;
- disney.last_used = 0;
+ disney.last_used = 0ms;
DISNEY_disable(0);
sec->AddDestroyFunction(&DISNEY_ShutDown, true);
diff --git a/src/hardware/gameblaster.cpp b/src/hardware/gameblaster.cpp
index 7911e3bbc..847b4223c 100644
--- a/src/hardware/gameblaster.cpp
+++ b/src/hardware/gameblaster.cpp
@@ -37,7 +37,7 @@ constexpr uint32_t GAMEBLASTER_CLOCK_HZ = 7159090;
//My mixer channel
static MixerChannel * cms_chan;
//Timer to disable the channel after a while
-static Bit32u lastWriteTicks;
+static system_tick_t lastWriteTicks;
static uint16_t cmsBase;
static saa1099_device* device[2];
@@ -73,7 +73,7 @@ static void CMS_CallBack(Bitu len) {
if ( cms_chan ) {
//Have there been 10 seconds of no commands, disable channel
- if ( lastWriteTicks + 10000 < PIC_Ticks ) {
+ if ( lastWriteTicks + 10000ms < PIC_Ticks ) {
cms_chan->Enable( false );
return;
}
diff --git a/src/hardware/hardware.cpp b/src/hardware/hardware.cpp
index 40f393134..324eda344 100644
--- a/src/hardware/hardware.cpp
+++ b/src/hardware/hardware.cpp
@@ -60,7 +60,7 @@ static struct {
FILE * handle;
Bit8u buffer[MIDI_BUF];
Bitu used,done;
- Bit32u last;
+ system_tick_t last;
} midi;
struct {
Bitu rowlen;
@@ -771,9 +771,9 @@ void CAPTURE_AddMidi(bool sysex, Bitu len, Bit8u * data) {
fwrite(midi_header,1,sizeof(midi_header),capture.midi.handle);
capture.midi.last=PIC_Ticks;
}
- Bit32u delta=PIC_Ticks-capture.midi.last;
+ const auto delta=PIC_Ticks-capture.midi.last;
capture.midi.last=PIC_Ticks;
- RawMidiAddNumber(delta);
+ RawMidiAddNumber(delta.count());
if (sysex) {
RawMidiAdd( 0xf0 );
RawMidiAddNumber( len );
diff --git a/src/hardware/innovation.cpp b/src/hardware/innovation.cpp
index ce5b89695..6e52e9649 100644
--- a/src/hardware/innovation.cpp
+++ b/src/hardware/innovation.cpp
@@ -98,7 +98,7 @@ void Innovation::Open(const std::string &model_choice,
channel = std::move(mixer_channel);
// Ready state-values for rendering
- last_used = 0;
+ last_used = 0ms;
play_buffer_pos = 0;
keep_rendering = true;
@@ -165,7 +165,7 @@ void Innovation::WriteToPort(io_port_t port, uint8_t data, io_width_t)
service->write(sid_port, data);
}
// Turn on the channel after the data's written
- if (!last_used) {
+ if (last_used > 0ms) {
channel->Enable(true);
}
last_used = PIC_Ticks;
@@ -215,8 +215,8 @@ void Innovation::MixerCallBack(uint16_t requested_samples)
play_buffer_pos += n;
}
// Stop the channel after 5 seconds of idle-time.
- if (last_used + 5000 < PIC_Ticks) {
- last_used = 0;
+ if (last_used + 5000ms < PIC_Ticks) {
+ last_used = 0ms;
channel->Enable(false);
}
}
diff --git a/src/hardware/innovation.h b/src/hardware/innovation.h
index f56cc1a9e..3bb297405 100644
--- a/src/hardware/innovation.h
+++ b/src/hardware/innovation.h
@@ -33,6 +33,7 @@
#include "mixer.h"
#include "inout.h"
#include "rwqueue.h"
+#include "timer.h"
#include "../libs/residfp/SID.h"
class Innovation {
@@ -75,7 +76,7 @@ private:
uint16_t base_port = 0;
double chip_clock = 0;
double sid_sample_rate = 0;
- size_t last_used = 0;
+ system_tick_t last_used = 0ms;
uint16_t play_buffer_pos = 0;
bool is_open = false;
};
diff --git a/src/hardware/joystick.cpp b/src/hardware/joystick.cpp
index 18e95c06c..e82622afe 100644
--- a/src/hardware/joystick.cpp
+++ b/src/hardware/joystick.cpp
@@ -26,6 +26,7 @@
#include "inout.h"
#include "pic.h"
#include "support.h"
+#include "timer.h"
//TODO: higher axis can't be mapped. Find out why again
@@ -33,7 +34,7 @@
#define SUPPORT_MAP_AUTO 0
constexpr int RANGE = 64;
-constexpr int TIMEOUT = 10;
+constexpr auto TIMEOUT = 10ms;
enum MovementType {
JOYMAP_SQUARE,
@@ -159,7 +160,7 @@ struct JoyStick {
JoystickType joytype = JOY_UNSET;
static JoyStick stick[2];
-static uint32_t last_write = 0;
+static system_tick_t last_write = 0ms;
static bool write_active = false;
static bool swap34 = false;
bool button_wrapping_enabled = true;
diff --git a/src/hardware/pic.cpp b/src/hardware/pic.cpp
index 7a555dd9e..079aedcba 100644
--- a/src/hardware/pic.cpp
+++ b/src/hardware/pic.cpp
@@ -134,7 +134,7 @@ struct PIC_Controller {
static PIC_Controller pics[2];
static PIC_Controller &primary_controller = pics[0];
static PIC_Controller &secondary_controller = pics[1];
-uint32_t PIC_Ticks = 0;
+system_tick_t PIC_Ticks = 0ms;
uint32_t PIC_IRQCheck = 0; // x86 dynamic core expects a 32 bit variable size
void PIC_Controller::set_imr(Bit8u val) {
@@ -617,7 +617,7 @@ public:
PIC_8259A(Section* configuration):Module_base(configuration){
/* Setup pic0 and pic1 with initial values like DOS has normally */
PIC_IRQCheck = 0;
- PIC_Ticks = 0;
+ PIC_Ticks = 0ms;
Bitu i;
for (i=0;i<2;i++) {
pics[i].auto_eoi=false;
diff --git a/src/hardware/ps1audio.cpp b/src/hardware/ps1audio.cpp
index d22303466..005eb840f 100644
--- a/src/hardware/ps1audio.cpp
+++ b/src/hardware/ps1audio.cpp
@@ -88,7 +88,7 @@ private:
uint8_t fifo[fifo_size] = {};
// Counters
- size_t last_write = 0;
+ system_tick_t last_write = 0ms;
uint32_t adder = 0;
uint32_t bytes_pending = 0;
uint32_t read_index_high = 0;
@@ -103,16 +103,16 @@ private:
bool can_trigger_irq = false;
};
-static void keep_alive_channel(size_t &last_used_on, mixer_channel_t &channel)
+static void keep_alive_channel(system_tick_t &last_used_on, mixer_channel_t &channel)
{
last_used_on = PIC_Ticks;
if (!channel->is_enabled)
channel->Enable(true);
}
-static void maybe_suspend_channel(const size_t last_used_on, mixer_channel_t &channel)
+static void maybe_suspend_channel(const system_tick_t last_used_on, mixer_channel_t &channel)
{
- const bool last_used_five_seconds_ago = PIC_Ticks > last_used_on + 5000;
+ const bool last_used_five_seconds_ago = PIC_Ticks > last_used_on + 5000ms;
if (last_used_five_seconds_ago)
channel->Enable(false);
}
@@ -141,7 +141,7 @@ Ps1Dac::Ps1Dac()
// Operate at native sampling rates
sample_rate = channel->GetSampleRate();
- last_write = 0;
+ last_write = 0ms;
Reset(true);
}
@@ -354,7 +354,7 @@ private:
sn76496_device device;
static constexpr auto max_samples_expected = 64;
int16_t buffer[1][max_samples_expected];
- size_t last_write = 0;
+ system_tick_t last_write = 0ms;
};
Ps1Synth::Ps1Synth() : device(machine_config(), 0, 0, clock_rate_hz)
@@ -370,7 +370,7 @@ Ps1Synth::Ps1Synth() : device(machine_config(), 0, 0, clock_rate_hz)
auto sample_rate = static_cast<int32_t>(channel->GetSampleRate());
device.convert_samplerate(sample_rate);
- last_write = 0;
+ last_write = 0ms;
}
void Ps1Synth::WriteSoundGeneratorPort205(io_port_t, uint8_t data, io_width_t)
diff --git a/src/hardware/tandy_sound.cpp b/src/hardware/tandy_sound.cpp
index fe7ac1d00..ad798d002 100644
--- a/src/hardware/tandy_sound.cpp
+++ b/src/hardware/tandy_sound.cpp
@@ -95,7 +95,7 @@ constexpr uint16_t TDAC_DMA_BUFSIZE = 1024;
static struct {
MixerChannel *chan = nullptr;
bool enabled = false;
- Bitu last_write = 0u;
+ system_tick_t last_write = 0ms;
struct {
MixerChannel *chan = nullptr;
bool enabled = false;
@@ -143,7 +143,7 @@ static void SN76496Update(uint16_t length)
return;
// Disable the channel if it's been quiet for a while
- if ((tandy.last_write + 5000) < PIC_Ticks) {
+ if ((tandy.last_write + 5000ms) < PIC_Ticks) {
tandy.enabled=false;
tandy.chan->Enable(false);
return;